python - 无法使用 privoxy 和 stem 从 Tor 获取新的 ip

标签 python web-scraping tor

我正在尝试使用 Tor、Privoxy 和 Stem 轮换 ip,但我最终得到的总是相同的 ip。我尝试了几件事(更改代理、使用请求 session 等等)但没有成功。

这是我的 python 代码:

import requests
from stem import Signal
from stem.control import Controller

with Controller.from_port(port = 9051) as controller:
  controller.authenticate('mykey')
  controller.signal(Signal.NEWNYM)

#proxies = {
#  "http": "http://127.0.0.1:8118"
#}

proxies = {
    'http': 'socks5h://127.0.0.1:9050',
    'https': 'socks5h://127.0.0.1:9050'
}

headers = {
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.73.11 (KHTML, like Gecko) Version/7.0.1 Safari/537.73.11'
}
r = requests.get("http://icanhazip.com", proxies=proxies, headers=headers, stream=False)
print (r.text)

.torc 文件有这个配置

ExitNodes {ar}
StrictNodes 1

ControlPort 9051
HashedControlPassword 16:BA2B8B2EAC4B391060A6FAA27FA922706F08D0BA0115D79840265D9DC3

privoxy 配置文件有这一行

forward-socks5   /               127.0.0.1:9050 .

最佳答案

我发现了问题。 IP 路由工作正常,问题是我一直在使用 {ar} 的 ExitNodes,而阿根廷只有一个节点。因此,它始终是相同的 IP。

关于python - 无法使用 privoxy 和 stem 从 Tor 获取新的 ip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53412510/

相关文章:

python - 论文 "Deep inside convolutional networks: Visualising image classification models and saliency maps"的实现,Simonyan 等人

python - Twitter:如何提取包含符号 (!,%,$) 的推文?

python - 点击时抓取

python - 具有自定义 API View 的 Django 休息框架分页

python - _meta.get_all_field_names() 中的 GenericForeignKey 名称错误

python - 使用 python 通过我的个人服务器调用网络抓取时出错

python - 在 Linux/Windows 中使用 RSelenium 的 Tor 浏览器

node.js - TOR 网络的 nodejs 网站

nginx - 如何创建 .onion 网站?

python - Matplotlib Graphs下的渐变填充