如何在 Tor 实例中使用 Selenium 时更改 IP

发布于 2025-01-15 03:34:03 字数 797 浏览 4 评论 0原文

我尝试将 Selenium 与 Tor 实例一起使用,但我陷入了 Cloudflare 页面。所以我想更改 IP 地址,直到不需要 Cloudflare 检查为止。我使用下面的函数来更新 Tor 实例,但它不起作用。我导入了 Stem 和其他实用程序。

from stem import Signal
from stem.control import Controller
def renew_connection():
       with Controller.from_port(port = 9050) as controller:
       controller.authenticate(password="My authentication code")
       controller.signal(Signal.NEWNYM) 

在这里您可以看到我的首选项

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", False)
profile.update_preferences()

当我使用 renew_connection() 函数时,它给出了连接错误。那么您建议如何更新IP地址。

I was trying to use Selenium with a Tor instance but I got caught in the Cloudflare page. So I wanted to change the IP address until it doesn't require Cloudflare check. I used the function below to renew the Tor instance but it didn't work. I imported Stem and other utilities.

from stem import Signal
from stem.control import Controller
def renew_connection():
       with Controller.from_port(port = 9050) as controller:
       controller.authenticate(password="My authentication code")
       controller.signal(Signal.NEWNYM) 

Here you can see my preferences

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", False)
profile.update_preferences()

When I use the renew_connection() function it gives a connection error. So what do you suggest to renew the IP address.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文