- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要确认 Stem 是否可用于启动公开 127.0.0.1:port 的 Tor 进程,然后在 selenium 脚本上将其用作代理 (SOCKS)。
我正在使用 Python 3.4.2、Stem 1.3.0 和 Tor(tor-win32-tor-0.2.5.10 专家捆绑)在 Windows 上。
这段代码适用于标准的 SOCKS 代理。
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
profile = 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', 9000)
driver = webdriver.Firefox(profile)
driver.implicitly_wait(30)
driver.get('http://www.reddit.com')
但我无法设法让它与 Tor 一起工作作为我的代理。我试图创建一个 Tor 进程,并创建了它。但我真的不知道它是否正常工作。我的 tor_error_log.txt
# File: stem_process.py
import stem.process
import stem
stem.process.launch_tor_with_config(
config = {
'SocksPort': '9000',
'ControlPort': '9051',
'ExitNodes': '{us}',
'Log': [
'NOTICE stdout',
'ERR file c:\\tor-win32-tor-0.2.5.10\\Tor\\tor_error_log.txt',
],
},
tor_cmd = 'C:\\tor-win32-tor-0.2.5.10\\Tor\\tor.exe',
)
然后我尝试了两种方法来创建连接或进行身份验证。第一个是使用 with
和 stem.control.controller
。第二个在较低级别,带有 stem.socket
和 stem.connection
第一个:
# File: stem_test1.py
from stem.control import Controller
with Controller.from_port(address='127.0.0.1', port=9051) as controller: #port = 9051
controller.authenticate()
print("Tor is running version %s" % controller.get_version())
'''
# Output:
Tor is running version 0.2.5.10 (git-13318a95ddfbbf8d)
'''
第二个:
# File: stem_test2.py
import sys
import stem
import stem.connection
import stem.socket
if __name__ == '__main__':
try:
control_socket = stem.socket.ControlPort(port = 9051)
stem.connection.authenticate(control_socket)
except stem.SocketError as exc:
print('Unable to connect to tor on port 9051: %s' % exc)
sys.exit(1)
except stem.connection.AuthenticationFailure as exc:
print('Unable to authenticate: %s' % exc)
sys.exit(1)
print("Issuing 'GETINFO version' query...\n")
control_socket.send('GETINFO version')
print(control_socket.recv())
'''
# Output:
Issuing 'GETINFO version' query...
version=0.2.5.10 (git-13318a95ddfbbf8d)
OK
'''
并且两者都运行无误...但是当我使用代码调用 Firefox WebDriver 实例时 127.0.0.1:9000
作为代理(也尝试使用 127.0.0.1:9051
,因为我真的不知道 socksPort
和 controlPort
之间的区别)它不起作用。
最佳答案
Stem 无法创建 tor 进程,它只是一个用于通过控制端口连接到现有 tor 服务器以进行检查/控制的库。
要创建 tor 进程本身,您需要让您的系统使用 upstart/launchctl/etc 启动它。或者,如果安装了 tor
,您只需在命令行中输入它,它就会在前台运行。
这样,要使用 stem,您需要将 torrc 编辑为 a.启用 ControlPort,和 b。设置身份验证方法(存储在您的 torrc 中的 cookieauth 或散列密码)。默认的 tor SocksPort 是 9050,ControlPort 是 9051。
SocksPort 是您路由流量(即 firefox)的端口,ControlPort 是您连接到的端口。请注意,只有当你甚至需要 stem 时,因为它看起来就像你试图用它启动一个 tor 实例(那是不可能的),如果你让它在你的系统 vanilla 上运行,它会与配置好的 selenium/firefox(好吧,默认端口是 9050 而不是 9000)
关于python - Selenium WebDriver + Tor 作为 Stem 的代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28651889/
我正在寻找克罗地亚语词干算法的实现。理想情况下使用 Java,但我也接受任何其他语言。 是否有一个讲英语的开发人员社区正在为克罗地亚语开发搜索应用程序? 谢谢 最佳答案 斯拉夫语言高度inflecti
我希望使用基于日期时间的 matplotlib 绘制一个主干。但似乎发生了错误:示例代码: import matplotlib.pyplot as plt from dateutil import p
所以基本上我有两个具有相同数字(16 位数字)的 .txt 文件,前 8 位数字全部相同(例如 12345678),然后接下来的 8 位数字是随机的(例如 38462943)。我一直在尝试做的是将两个
以下问题看起来很像 SO 上已有的许多相关问题(我已经通读了它们,但我的问题略有不同并且仍然存在)。 我使用 stem 库在 Python 3.6.1 中编写了以下代码(在 macOS Sierra
我正在尝试获取 To Russia With Love tutoial来自 Stem 项目工作。 from io import StringIO import socket import urllib
作为代码的一部分,我的功能如下: def match_output(orig_path: Path,lines: Iterable[str],stem: str, delim: str,delim_p
我在将 tor 与 python 结合使用时遇到了一些问题,我不太清楚从这里该何去何从。 系统/包:Windows 10 Python 3.8(通过 jupyter 实验室) 茎 tor(tor.ex
我想将 EELS 数据立方体的强度与厚度图相乘。我尝试使用简单的数学命令,但我只获得了第一个切片的结果。我认为计算就像执行 Result(x,y,E) = SI(x,y,E) * Thickness(
我看过其他关于此问题的帖子,但我仍然无法让它发挥作用。 http://snowball.tartarus.org/dist/libstemmer_java.tgz <<- 这包含 porter2 算法
我正在处理一些 nlp 任务。我的输入是法语文本,因此在我的上下文中只能使用 Snowball Stemmer。但是,不幸的是,它一直给我糟糕的词干,因为它甚至不会删除 plural "s" 或 si
如何在没有标记(仅 Steam 线)的情况下绘制 Steam 图?。它在绘制非常长的信号阵列时特别有用。 谢谢! 最佳答案 您可以简单地将标记设置为空: import matplotlib.pyplo
我正在尝试设置 Makefile 以根据目标文件扩展名构建静态 (.a) 和动态 (.so) 库。 我以前只将以下 Makefile 用于静态库: NAME := config LIB :=
我知道词干提取和词形还原如下: 词干 - 将单词转换成不变的部分;有趣,娱乐 - 有趣 lemmatizing - 将单词转换为字典形式;有趣的,逗乐的 我可以理解为什么要使用词形还原。但我不明白做词
我正在使用 Boost 文件系统库。 我有一条路 boost::filesystem::path P("/foo/bar.baz"); 我想将路径 p 的词干部分修改为“bar_quz”,因此路径 P
我正在尝试使用斯坦福词性标注器和 NER 编写一个关键字提取程序。对于关键字提取,我只对专有名词感兴趣。这是基本方法 通过删除字母以外的任何内容来清理数据 删除停用词 对每个单词进行词干 确定每个单词
我对 python 很陌生,没有真正的编程知识。在我目前的工作中,我被要求从大约 500 多个文件中获取文本形式的数据并将它们绘制出来。我在一定程度上理解绘图,但我似乎无法弄清楚如何以易于选择特定部分
我在远程服务器 (Ubuntu) 上运行 Tor,端口为 9150,控制端口为 9151。我已确认两者都在通过 netstat -ant 运行。 这是我的代码,它引发了 SOCKS5Error: 0x
我正在使用 stem 来控制使用 stem.process.launch_tor_with_config 创建的 tor 节点。我还创建了一个在上述进程的控制端口上运行的 stem.control.C
关闭。这个问题需要更多 focused .它目前不接受答案。 想要改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this q
我一直在尝试将 InceptionResnetV2 中的 Keras implementation 模型摘要与他们论文中指定的模型摘要进行比较,当涉及到 filter_concat block 时,它
我是一名优秀的程序员,十分优秀!