Your Name 3 năm trước cách đây
mục cha
commit
989b6622b6
1 tập tin đã thay đổi với 42 bổ sung8 xóa
  1. 42 8
      monitor/hhh_404.py

+ 42 - 8
monitor/hhh_404.py

@@ -1,19 +1,53 @@
 from seleniumwire import webdriver  # Import from seleniumwire
-
+import time
+import requests
+import sys
 # Create a new instance of the Chrome driver
-driver = webdriver.Chrome()
+
+headers = {
+        "Authorization": "Bearer " + "Vt5YH5YvMwfz2m5KSpFMLLnJXoAM4uR7Ls5EQ68fw3l",
+        "Content-Type": "application/x-www-form-urlencoded"
+}
+
+
+def send_msg(kw,original_url):
+    params = {"message": "HHH破圖偵測: "+kw+" 頁面:"+original_url}
+    r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
+
+
+#original_url='https://hhh.com.tw/columns/detail/4300/'
+#original_url='https://www.hhh.com.tw/'
+original_url='https://m.hhh.com.tw/hhh-home-mb/index.html'
+
+
+options = webdriver.ChromeOptions()
+options.add_argument('--headless')
+options.add_argument('--disable-gpu')
+#options.add_argument('--incognito')
+# options.add_argument('--no-sandbox')
+options.add_argument('--disable-dev-shm-usage')
+driver = webdriver.Chrome(desired_capabilities=options.to_capabilities())
+
 
 # Go to the Google home page
-driver.get('https://hhh.com.tw/cases/detail/d/12428/')
+#driver.get('https://hhh.com.tw/cases/detail/d/12428/')
+driver.get(original_url)
 
+time.sleep(15)
 # Access requests via the `requests` attribute
 for request in driver.requests:
     if request.response:
         if int(request.response.status_code)>=404:
-            print(
-                request.url,
-                request.response.status_code,
-                request.response.headers['Content-Type']
-            )
+            if 'jpg' in request.url or 'png' in request.url:
+                send_msg(request.url,original_url)
+                print(
+                    request.url,
+                    request.response.status_code,
+                    request.response.headers['Content-Type']
+                )
+
+driver.quit()
+sys.exit()            
 #        else:
 #            print(request.url)
+