Open tor browser with selenium

后端 未结 10 1098
长发绾君心
长发绾君心 2020-12-02 09:15

Is it possible to make selenium use the TOR browser? Does anyone have any code they could copy-paste?

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 10:02

    //just check your tor browser's port number and change that accordingly in the //code

    from selenium import webdriver
    profile=webdriver.FirefoxProfile()
    profile.set_preference('network.proxy.type', 1)
    profile.set_preference('network.proxy.socks', '127.0.0.1')
    profile.set_preference('network.proxy.socks_port', 9150)
    browser=webdriver.Firefox(profile)
    browser.get("http://yahoo.com")
    browser.save_screenshot("screenshot.png")
    browser.close()
    

提交回复
热议问题