# -*- coding:utf-8 -*- from selenium import webdriver from selenium.webdriver.common.proxy import Proxy, ProxyType import time # 配置代理 proxy = Proxy() proxy.proxy_type = ProxyType.MANUAL proxy.http_proxy = "http://localhost:10809" # 创建 Chrome WebDriver 实例,并添加代理选项 chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("--proxy-server=http://localhost:10809") chrome_options.add_argument('--headless') # 创建 WebDriver driver = webdriver.Chrome(options=chrome_options) # 打开网页 url = 'https://www.baidu.com' # 替换为实际网页的 URL driver.get(url) # 等待页面加载(可根据实际情况调整) time.sleep(3) network = driver.execute_script("return window.performance.getEntries();") for data in network: if data["name"].startswith("http"): print(data["name"]) driver.quit()
Python下通过代理抓取F12模式下network的请求
于 2023-11-14 14:09:16 首次发布