ads-selenium.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. from seleniumwire import webdriver
  2. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  3. import time
  4. import os
  5. import urllib.parse
  6. from selenium.webdriver.support.ui import WebDriverWait
  7. from selenium.webdriver.common.by import By
  8. from selenium.webdriver.common.keys import Keys
  9. from selenium.webdriver.support import expected_conditions as EC
  10. import codecs
  11. import random
  12. from bs4 import BeautifulSoup
  13. import requests
  14. import time
  15. import rpyc
  16. import sys
  17. import docker
  18. import gzip
  19. import brotli
  20. def restart_browser():
  21. # os.system('docker container restart headless-shell')
  22. # time.sleep(9)
  23. chrome_options = webdriver.ChromeOptions()
  24. # chrome_options.add_argument("--incognito")
  25. # chrome_options.add_argument("--headless")
  26. chrome_options.add_argument("--no-sandbox")
  27. chrome_options.add_argument("--disable-dev-shm-usage")
  28. chrome_options.add_argument("start-maximized")
  29. chrome_options.add_argument("user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data")
  30. chrome_options.add_argument("--user-profile=Profile 7")
  31. # chrome_options.debugger_address="127.0.0.1:9222"
  32. # chrome98=r'C:\portable\webdriver\chrome98\chromedriver.exe'
  33. # chrome98=r'/root/drivers/98/chromedriver'
  34. # driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chrome98)
  35. driver = webdriver.Chrome(chrome_options=chrome_options)
  36. return driver
  37. driver=restart_browser()
  38. #driver.get('https://ads.google.com/aw/campaigns?ocid=891665672&workspaceId=0&euid=459838964&__u=6055300436&uscid=891665672&__c=9718115528&authuser=1')
  39. driver.get('https://ads.google.com/aw/campaigns?ocid=400572474&euid=459838964&__u=6055300436&uscid=400572474&__c=7078600426&authuser=1')
  40. time.sleep(21)
  41. for request in driver.requests:
  42. if request.response:
  43. if 'Get?' in request.url :
  44. if 'Overview' in request.url :
  45. resp=request.response.body
  46. if 'gzip' in request.response.headers.get('Content-Encoding'):
  47. resp = gzip.decompress(request.response.body)
  48. if 'br' in request.response.headers.get('Content-Encoding'):
  49. resp = brotli.decompress(request.response.body)
  50. jstext = resp.decode('utf-8')
  51. print(jstext)
  52. fw=codecs.open('c:/tmp/json.txt','w','utf-8')
  53. fw.write(jstext)
  54. fw.close()
  55. # output = parsing_js(jstext)
  56. # time.sleep(1)
  57. time.sleep(9999)