简体   繁体   English

在phantomjs中使用代理(Selenium WebDriver)

[英]Using a proxy with phantomjs (selenium webdriver)

I'm using phantomJS as a driver for selenium. 我正在使用phantomJS作为硒的驱动程序。 My code is written in python. 我的代码是用python编写的。 I followed the advice from similar questions, and am using the following: 我遵循了类似问题的建议,并使用以下方法:

service_args = [
    '--proxy=78.23.244.145:80',
    '--proxy-type=http',
    ]
driver = webdriver.PhantomJS(service_args=service_args)
driver.get('http://www.whatismyip.com/')

However, when I print the html, barely anything shows up: 但是,当我打印html时,几乎没有显示任何内容:

print driver.page_source

OUTPUT: OUTPUT:

<html><head></head><body></body></html>

If I do this with just the usual call to phantomJS, the website shows up as usual: 如果仅通过对phantomJS的常规调用来执行此操作,则该网站将照常显示:

driver = webdriver.PhantomJS()

For reference, I've tried this with a bunch of proxies from this list: 作为参考,我尝试使用以下列表中的许多代理进行此操作:

http://proxylist.hidemyass.com/search-1291972#listable http://proxylist.hidemyass.com/search-1291972#listable

I'm wondering how to get the page to properly display when using a proxy. 我想知道如何使用代理时正确显示页面。 Any help would be appreciated! 任何帮助,将不胜感激!

I suspect that the proxy you are using is incorrect. 我怀疑您使用的代理不正确。 I tried the following where used proxy behave sanely in windows 8. 我尝试了以下使用代理在Windows 8中表现正常的情况。

from selenium.webdriver.common.proxy import *
from selenium import webdriver
from selenium.webdriver.common.by import By
phantomjs_path = r"E:\Software & Tutorial\Phantom\phantomjs-2.1.1-windows\bin\phantomjs.exe"
service_args = [
    '--proxy=217.156.252.118:8080',
    '--proxy-type=https',
    ]

driver = webdriver.PhantomJS(executable_path=phantomjs_path,service_args=service_args)
driver.get("https://www.google.com.bd/?gws_rd=ssl#q=what+is+my+ip")
print driver.page_source.encode('utf-8')
print "="*70
print driver.title
driver.save_screenshot(r"E:\Software & Tutorial\Phantom\test.png")
driver.quit()

See the saved image(test.png) and see the status. 查看保存的图像(test.png)并查看状态。 If used ip is blacklisted the google prompted captcha box see that image!! 如果使用的IP被列入黑名单,则Google提示的验证码框将显示该图像! IP has been changed!! IP已更改!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM