hhh_404.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from seleniumwire import webdriver # Import from seleniumwire
  2. import time
  3. import requests
  4. import sys
  5. # Create a new instance of the Chrome driver
  6. headers = {
  7. "Authorization": "Bearer " + "Vt5YH5YvMwfz2m5KSpFMLLnJXoAM4uR7Ls5EQ68fw3l",
  8. "Content-Type": "application/x-www-form-urlencoded"
  9. }
  10. def send_msg(kw,original_url):
  11. params = {"message": "HHH破圖偵測: "+kw+" 頁面:"+original_url}
  12. r = requests.post("https://notify-api.line.me/api/notify",headers=headers, params=params)
  13. #original_url='https://hhh.com.tw/columns/detail/4300/'
  14. #original_url='https://www.hhh.com.tw/'
  15. original_url='https://m.hhh.com.tw/hhh-home-mb/index.html'
  16. if len(sys.argv)>=2:
  17. original_url=sys.argv[1]
  18. print(original_url)
  19. options = webdriver.ChromeOptions()
  20. options.add_argument('--headless')
  21. options.add_argument('--disable-gpu')
  22. options.add_argument('--incognito')
  23. options.add_argument('--no-sandbox')
  24. options.add_argument('--disable-dev-shm-usage')
  25. #driver = webdriver.Chrome(desired_capabilities=options.to_capabilities())
  26. driver = webdriver.Chrome(chrome_options=options)
  27. # Go to the Google home page
  28. #driver.get('https://hhh.com.tw/cases/detail/d/12428/')
  29. driver.get(original_url)
  30. time.sleep(15)
  31. # Access requests via the `requests` attribute
  32. for request in driver.requests:
  33. if request.response:
  34. if int(request.response.status_code)>=404:
  35. if 'jpg' in request.url or 'png' in request.url:
  36. send_msg(request.url,original_url)
  37. print(
  38. request.url,
  39. request.response.status_code,
  40. request.response.headers['Content-Type']
  41. )
  42. driver.quit()
  43. sys.exit()
  44. # else:
  45. # print(request.url)