【问题标题】:selenium python runing firefox with TOR (windows)selenium python 使用 TOR (windows) 运行 firefox
【发布时间】:2015-05-15 16:18:30
【问题描述】:

我正在尝试使用 tor 运行 python selenium(firefox 驱动程序)。 我检查了这个链接 (Using Selenium WebDriver with Tor) 但这是 java 实现。 我对 selenium 比较陌生,在将 java 代码转换为 Python API 时遇到问题。

以前有人遇到过这个问题吗?

【问题讨论】:

  • 我没有遇到问题。 Selenium 与 Python 和 Tor 配合得很好。
  • 你能举个简单的例子吗?感谢重播!
  • 好吧好吧。稍后我会发布它作为答案。有机会请采纳。

标签: python selenium tor


【解决方案1】:

这是适用于我的 Python 2.7 代码(我上次更新它是在 2015 年 3 月 12 日)。作为额外的奖励,它会填写 agora 上的用户名和密码字段,并要求您填写您看到的验证码,然后单击提交按钮。您需要创建一个默认的 firefox profile,并将其代理设置为 tor (127.0.0.1:9050),并将该配置文件名称的路径填充到 startbrowser 函数分析器变量中:

from selenium import webdriver 
from selenium.webdriver.support.ui import Select, WebDriverWait
from selenium.common.exceptions import NoSuchFrameException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

username = 'agora username'
password = 'agora password'
def go_to_page(br):
    #page_num = page_num - 1
    #start_results = page_num * 100
    #start_results = str(start_results)
    url = 'http://agorahooawayyfoe.onion'
    print '[*] loading url: '+url
    br.get(url)
    #br.get_screenshot_as_file('agora.tiff')
    usernamed = br.find_element_by_name("username")
    usernamed.send_keys(username) # password
    passwordd = br.find_element_by_name("password") # enterCaptcha
    passwordd.send_keys(password)
    captchad = br.find_element_by_name("enterCaptcha")
    capt = raw_input('enter captcha you see on screen: ')
    captchad.send_keys(capt)
    br.implicitly_wait(3)
    br.find_element_by_name("submit").click()

def start_browser():
    profiler = webdriver.FirefoxProfile('/Users/your username/Library/Application Support/Firefox/Profiles/vxh0qxtt.tor')
    br = webdriver.Firefox(firefox_profile=profiler)
    br.implicitly_wait(10)
    return br

def main():
    br = start_browser()
    go_to_page(br)

main()

【讨论】:

  • 您好,感谢它帮助我分配的代码!我没有正确使用配置文件。谢谢您的帮助!!!!对我来说,我需要将端口更改为 9150。
  • @dubin 真棒很高兴听到
  • 我收到此错误 PermissionError: [WinError 5] Access is denied
猜你喜欢
  • 2017-05-08
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-10
  • 1970-01-01
  • 1970-01-01
  • 2012-01-08
  • 1970-01-01
相关资源
最近更新 更多