from seleniumwire import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities import time import os import urllib.parse from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions as EC import codecs import random from bs4 import BeautifulSoup import requests import time import rpyc import sys import docker import gzip import brotli def restart_browser(): # os.system('docker container restart headless-shell') # time.sleep(9) chrome_options = webdriver.ChromeOptions() # chrome_options.add_argument("--incognito") # chrome_options.add_argument("--headless") chrome_options.add_argument("--no-sandbox") chrome_options.add_argument("--disable-dev-shm-usage") chrome_options.add_argument("start-maximized") chrome_options.add_argument("user-data-dir=C:\\Users\\jared\\AppData\\Local\\Google\\Chrome\\User Data") chrome_options.add_argument("--user-profile=Profile 7") # chrome_options.debugger_address="127.0.0.1:9222" # chrome98=r'C:\portable\webdriver\chrome98\chromedriver.exe' # chrome98=r'/root/drivers/98/chromedriver' # driver = webdriver.Chrome(chrome_options=chrome_options,executable_path=chrome98) driver = webdriver.Chrome(chrome_options=chrome_options) return driver driver=restart_browser() #driver.get('https://ads.google.com/aw/campaigns?ocid=891665672&workspaceId=0&euid=459838964&__u=6055300436&uscid=891665672&__c=9718115528&authuser=1') driver.get('https://ads.google.com/aw/campaigns?ocid=400572474&euid=459838964&__u=6055300436&uscid=400572474&__c=7078600426&authuser=1') time.sleep(21) for request in driver.requests: if request.response: if 'Get?' in request.url : if 'Overview' in request.url : resp=request.response.body if 'gzip' in request.response.headers.get('Content-Encoding'): resp = gzip.decompress(request.response.body) if 'br' in request.response.headers.get('Content-Encoding'): resp = brotli.decompress(request.response.body) jstext = resp.decode('utf-8') print(jstext) fw=codecs.open('c:/tmp/json.txt','w','utf-8') fw.write(jstext) fw.close() # output = parsing_js(jstext) # time.sleep(1) time.sleep(9999)