微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在使用Tor的SeleniumPython中建立新的标识?

如何解决如何在使用Tor的SeleniumPython中建立新的标识?

我知道已经有一些“解决方案”,但是正如您从注释中看到的(例如:How to change Tor identity in Python?),它们通常不是最新的,或者只是行不通

所以我再次问了这个问题(在2020年):我想使用Tor浏览器自动访问网站,但是在半小时后,我需要更改身份,以便获得新的IP。

这是我的代码,我可以使用该代码自动访问网站:

import os
import time
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.support.ui import webdriverwait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


torexe = os.popen(r'C:\Users\Max\Desktop\Tor_browser\browser\Torbrowser\Tor\tor.exe')
profile = FirefoxProfile(r'C:\Users\Max\Desktop\Tor_browser\browser\Torbrowser\Data\browser\profile.default')
profile.set_preference('network.proxy.type',1)
profile.set_preference('network.proxy.socks','127.0.0.1')
profile.set_preference('network.proxy.socks_port',9050)
profile.set_preference("network.proxy.socks_remote_dns",True)
profile.set_preference("browser.download.folderList",2)
profile.set_preference('permissions.default.image',2)
profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so','false')
options = webdriver.firefox.options.Options()
options.headless = True
profile.update_preferences()
browser = webdriver.Firefox(firefox_profile=profile,options=options,executable_path=r'C:\Users\Max\Downloads\geckodriver-v0.27.0-win64\geckodriver.exe')


browser.get("https://www.website.com/")

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。