有没有办法直接在运行 Selenium 的 Python 脚本上使用 Torsocks?

问题描述

我有一个运行 Selenium 的简单 Python 脚本,我尝试使用 Torsocks(像往常一样),就像这样:torsocks python script.py。但是,它因以下错误而失败:

Traceback (most recent call last):
  File "script.py",line 21,in <module>
    browser = webdriver.Firefox(options=options)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py",line 163,in __init__
    log_path=service_log_path)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/service.py",line 47,in __init__
    self,executable_path,port=port,log_file=log_file,env=env)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py",line 42,in __init__
    self.port = utils.free_port()
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/utils.py",line 37,in free_port
    free_socket.listen(5)
PermissionError: [Errno 1] Operation not permitted

真的可以像这样使用 Torsocks 吗?

我意识到我可以使用 SOCKS5 代理发送请求,但我想知道它是否可以使用 Torsocks 运行,如果不能,最好能得到解释。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)