小编Tom*_*ins的帖子

使用TOR来获取代理的Python硒适用于Firefox,但不适用于Chrome

在过去的几天里,我一直在与python一起玩耍,向youtube学习,并决定创建一些我想自动化的东西。

我发现了一个小问题-在Firefox浏览器中使用python脚本时,我可以在后台打开Tor浏览器并使用以下代码:

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)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
browser = webdriver.Firefox(firefox_profile=profile)
Run Code Online (Sandbox Code Playgroud)

一切正常,每次打开带有新IP的Web浏览器。现在,我使用此代码在Chrome上尝试了相同的操作

PROXY = "127.0.0.1:9150" # IP:PORT or HOST:PORT
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)
chrome = webdriver.Chrome(chrome_options=chrome_options)
Run Code Online (Sandbox Code Playgroud)

我已经使用常规代理(不是来自tor)测试了此代码,并且它们确实起作用了。

当我这样做时,Chrome就会发生以下情况:http : //prntscr.com/kf8vzt

我当时在想,为什么它不能在Firefox上运行,而在Firefox上却不能运行,却发现Tor是基于Firefox编写的?(我可能是错的,如果是,请更正此错误)。

是否可以在Chrome中使用它?

在Chrome设置中,只是尝试在内部进行设置

python proxy selenium tor

8
推荐指数
1
解决办法
2256
查看次数

标签 统计

proxy ×1

python ×1

selenium ×1

tor ×1