首页 > 解决方案 > 每次我发出请求时如何使用 Tor 更改 Selenium 的 IP 地址

问题描述

通过这些代码行,我可以用 Tor 屏蔽我的公共 ip。

def function():
    os.system("taskkill /f tor")
    torexe = os.popen(r'C:\Users\myuser\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
    PROXY = "socks5://localhost:9050"
    options = webdriver.ChromeOptions()
    options.add_argument('--proxy-server=%s' % PROXY)
    driver = webdriver.Chrome(chrome_options=options, executable_path=r"C:/Program Files (x86)/chromedriver.exe")
    driver.get("https://www.mikes-marketing-tools.com/whatismyip.php")

我需要每次执行此功能时,公共IP都会更改(使用tor)。我怎么能那样做?

标签: pythonseleniumtor

解决方案


推荐阅读