簡體   English   中英

在python中使用Selenium,PhantomJS和Tor

[英]Using Selenium, PhantomJS and Tor in python

我正在嘗試使用含有硒和Tor的phantomJS。 我有以下內容:

from selenium import webdriver
service_args = [
        '--proxy=127.0.0.1:9050',
        ' --proxy-type=socks5',
    ]
driver = webdriver.PhantomJS(service_args = service_args)

每次我嘗試連接時,都會收到以下錯誤消息:

WebDriverException                        Traceback (most recent call last)
<ipython-input-2-98e27eb2ae26> in <module>()
  4             ' --proxy-type=socks5',
  5     ]
----> 6 driver = webdriver.PhantomJS(service_args = service_args)

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs    /webdriver.pyc in __init__(self, executable_path, port, desired_capabilities,    service_args, service_log_path)
 49         self.service = Service(executable_path, port=port,
 50             service_args=service_args, log_path=service_log_path)
---> 51         self.service.start()
 52 
 53         try:

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.pyc in start(self)
 83         count = 0
 84         while True:
---> 85             self.assert_process_still_running()
 86             if self.is_connectable():
 87                 break

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.pyc in assert_process_still_running(self)
 96             raise WebDriverException(
 97                 'Service %s unexpectedly exited. Status code was: %s'
---> 98                 % (self.path, return_code)
 99             )
100 

WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: 255

PhantomJS和Selenium可以與Tor參數一起使用。 任何幫助,讓這項工作將不勝感激!

這是一個舊的,但我來到這里,因為我搜索了你想要做的事情。

當我執行你的代碼時,我得到了完全相同的行為。

只需刪除第二個參數的空格('--proxy-type = socks5'),您的代碼就可以正常運行。

從而,

from selenium import webdriver
    service_args = [
        '--proxy=127.0.0.1:9050',
        '--proxy-type=socks5',
    ]
    driver = webdriver.PhantomJS(service_args = service_args)

嘗試添加您的確切phantomjs路徑?

driver = webdriver.PhantomJS(executable_path=<your_phantomjs_path>, service_args = service_args)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM