更改 IP 地址 Python Selenium

Luc*_*pes 2 python proxy selenium web-crawler

我尝试使用 Python Selenium 运行代码

from selenium import webdriver
import time

profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy_type",1)
profile.set_preference("network.proxy.http","124.240.187.80")
profile.set_preference("network.proxy.http_port",82)
profile.update_preferences()

driver=webdriver.Firefox(firefox_profile=profile)
driver.get('https://www.whatismyip.com/')
driver.sleep(3)
driver.close()
Run Code Online (Sandbox Code Playgroud)

但是当你运行这个文件时我的IP地址不会改变。

我怎样才能更改我的IP地址。我正在开发一个网络爬虫,需要更改ip

小智 5

使用 FF 所需的功能。

proxy = "124.240.187.80:82"

webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
   "httpProxy":proxy,
   "ftpProxy":proxy,
   "sslProxy":proxy,
   "noProxy":None,
   "proxyType":"MANUAL",
   "class":"org.openqa.selenium.Proxy",
   "autodetect":False
}
Run Code Online (Sandbox Code Playgroud)

WebDriver:高级用法 - 代理

  • 谷歌浏览器如何做到这一点 (4认同)