[英]Setting a proxy using python, selenium, and phantomJS
I have tried the solution posted by Alex on the following page but I keep getting this error. 我已经尝试过由Alex在下一页上发布的解决方案,但我一直收到此错误。 How do I set a proxy for phantomjs/ghostdriver in python webdriver? 如何在python webdriver中为phantomjs / ghostdriver设置代理?
I have phantomJS in my PATH. 我的PATH中有phantomJS。
File "C:\Users\sri19\Desktop\Gui OSRS\testphantomproxy.py", line 21, in <module>
driver = webdriver.PhantomJS(service_args=phan_args, desired_capabilities=dcap)
File "C:\Python27\Lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 52, in __init__
self.service.start()
File "C:\Python27\Lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
self.assert_process_still_running()
File "C:\Python27\Lib\site-packages\selenium\webdriver\common\service.py", line 99, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service phantomjs unexpectedly exited. Status code was: -1
Here is my current test script 这是我当前的测试脚本
from selenium import webdriver
from selenium.webdriver.common.proxy import *
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import StaleElementReferenceException, TimeoutException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
import sys
singleproxy = "88.157.149.250:8080"
proxytype = "http"
user_agent = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) " + "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36")
phan_args = ['--proxy=88.157.149.250:8080', 'proxy-type=http']
print "step 1"
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = user_agent
print "step 2"
driver = webdriver.PhantomJS(service_args=phan_args, desired_capabilities=dcap)
driver.get("https://www.whatismyip.com/")
print "step 3"
print driver.current_url
htmlpage = driver.page_source
print htmlpage.encode(sys.stdout.encoding, errors='replace')
Can anyone help me understand why I am receiving this error? 谁能帮助我了解为什么我收到此错误? When I applied this proxy to chromedriver (through a different method) it worked. 当我将此代理应用于chromedriver(通过另一种方法)时,它起作用了。 So it cannot be the proxy. 因此它不能是代理。
Whelp... Made a small mistake. 小子...犯了一个小错误。
The following line phan_args = ['--proxy=88.157.149.250:8080', 'proxy-type=http'] should be phan_args = ['--proxy=88.157.149.250:8080', '--proxy-type=http'] 以下行phan_args = ['--proxy = 88.157.149.250:8080','proxy-type = http']应该是phan_args = ['--proxy = 88.157.149.250:8080','--proxy-type = http']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.