selenium获取network列表
2022-06-14 python 2420
from selenium import webdriver import time import os from browsermobproxy import Server start = time.time() path = os.path.dirname(os.path.realpath(__file__)) #https://github.com/lightbody/browsermob-proxy/releases/tag/browsermob-proxy-2.1.4 BMPserver = Server(path + '/soft/browsermob-proxy-2.1.4/bin/browsermob-proxy.bat') BMPserver.start() BMPproxy = BMPserver.create_proxy() userPath = os.path.join(path, "user") chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--user-data-dir=" + userPath); chrome_options.add_argument('--proxy-server={}'.format(BMPproxy.proxy)) chrome_options.add_argument('--ignore-certificate-errors') chrome_options.add_argument('--ignore-urlfetcher-cert-requests') # chrome_options.add_argument("--headless") # chrome_options.add_argument("--disable-gpu") # http://chromedriver.storage.googleapis.com/index.html driver = webdriver.Chrome(executable_path=path + r"/soft/chromedriver.exe", options=chrome_options) url = "http://www.xxxx.com/" BMPproxy.new_har("video", options={"captureContent": True}) driver.get(url) json_data = BMPproxy.har time.sleep(3) for entry in json_data['log']['entries']: entry_url = entry['request']['url'] print(entry_url) driver.quit() end = time.time() print(" 用时:%d 秒" % (end - start,))
很赞哦! (0)
相关文章
文章评论
-
-
-
0条评论