在Python中使用Selenium和Browsermob代理进行抓取时,如何使用代理IP?
我希望在python中使用Selenium和Browsermob代理进行web抓取时能够监视网络请求,但我无法更改chrome浏览器的IP,因此发送到网站的请求不是来自我的IP地址,而是来自我设置的地址 当Browsermob代理拦截来自不同IP的请求时,有没有办法让我监视网络数据在Python中使用Selenium和Browsermob代理进行抓取时,如何使用代理IP?,python,selenium,web-scraping,proxy,browsermob-proxy,Python,Selenium,Web Scraping,Proxy,Browsermob Proxy,我希望在python中使用Selenium和Browsermob代理进行web抓取时能够监视网络请求,但我无法更改chrome浏览器的IP,因此发送到网站的请求不是来自我的IP地址,而是来自我设置的地址 当Browsermob代理拦截来自不同IP的请求时,有没有办法让我监视网络数据 def create_browsermob_proxy(): for proc in psutil.process_iter(): # check whether the process name
def create_browsermob_proxy():
for proc in psutil.process_iter():
# check whether the process name matches
if proc.name() == "browsermob-proxy":
proc.kill()
dict = {'port': 8080}
server = Server(path="C:/Path/To/File/browsermob-proxy.bat", options=dict)
server.start()
proxy = server.create_proxy()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--proxy-server={}".format(proxy.proxy))
driver = webdriver.Chrome(chrome_options=chrome_options)
proxy.new_har("google")
driver.get("http://www.google.com")
print(proxy.har)
可能重复的