【问题标题】:Scrapy-Splash with Tor使用 Tor 的 Scrapy-Splash
【发布时间】:2017-02-16 07:46:05
【问题描述】:

我已经使用这个链接成功地用 Tor 运行了 Scrapy:http://pkmishra.github.io/blog/2013/03/18/how-to-run-scrapy-with-TOR-and-multiple-browser-agents-part-1-mac/

但我无法使用 Tor 运行 Splash。

在 Scrapy-settings.py 中,我针对 http_proxy(8123 是 polipo 端口)定向到 polipo:

HTTP_PROXY = 'http://127.0.0.1:8123'

在 polipo.config 中,我定向到了 tor(9150 是 tor 端口):

socksParentProxy = localhost:9150

diskCacheRoot=""

非常适合scrapy。在飞溅中它不起作用。但我不得不说 splash 或 docker 使用 polipo 来作为 http_proxy,就像在 scrapy-settings.py 中一样。 Docker 应该以某种方式使用 polipo,而 polipo 将直接指向 tor。我该怎么做?

我用以下方式运行飞溅:

sudo docker run -p 5023:5023 -p 8050:8050 -p 80511 scrapinghub/splash

在 etc/default/docker 中,我尝试使用 docker 将其定向到 polipo:

export http_proxy='http://127.0.0.1:8123'
Environment="http_proxy=http://127.0.0.1:8123"

但我没能成功。我究竟做错了什么?谢谢:)

【问题讨论】:

    标签: scrapy tor scrapy-splash splash-js-render polipo


    【解决方案1】:

    你需要

    1. 让 Tor 可以从 Splash Docker 容器中访问;
    2. 告诉 Splash 使用这个 Tor 代理。

    对于 (2),您可以使用 Splash proxy profiles 或直接设置代理,在 proxy 参数中,或在 splash:on_request 回调 Lua 脚本中使用 request:set_proxy。例如,如果 Tor 可以从 Splash Docker 容器中以 tor:8123 的形式访问,您可以执行如下请求:

    http://<splash-url>:8050/render.html?url=...&proxy=socks5://tor:8123
    

    另外,看看https://github.com/TeamHG-Memex/aquarium - 它设置了所有这些 - 它设置了“tor”代理配置文件,在另一个 Docker 容器中启动 Tor,并链接这些容器。要在通过 Aquarium 部署的 Splash 中使用 Tor 访问远程网站,您只需将 proxy=tor GET 参数添加到请求中:

    http://<splash-url>:8050/render.html?url=...&proxy=tor
    

    【讨论】:

    • 我是否必须在我的请求中包含'proxy': 'tor' 部分,例如:yield SplashRequest(auction_results_url, self.parse_auction_list, endpoint='execute', args = {'lua_source': self.lua_script, 'proxy': 'tor'} ) 如果请求真的通过 tor,我在日志中看不到
    • @mikhail-korobov 那么(1),如何在同一个 docker 容器中运行 splash 和 tor 或者如何使 tor 可以从 splash docker 容器中访问?
    • @KrishanKumarMourya 这是配置 Docker 的问题。 aquarium 使用 docker-compose 一次启动多个 Docker 容器(一些 Splash 容器、负载均衡器、tor)并使用“链接”功能连接它们
    猜你喜欢
    • 1970-01-01
    • 2017-05-27
    • 1970-01-01
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-23
    • 2018-01-08
    相关资源
    最近更新 更多