from selenium import webdriver
from selenium.webdriver import DesiredCapabilities



desired_capabilities= DesiredCapabilities.PHANTOMJS.copy()

headers = {
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.8',
'Cache-Control': 'max-age=0',
'Cookie': "a=b;c=d;e=f",
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
'Connection': 'keep-alive',
'Referer':'http://www.baidu.com/'
}
for key, value in headers.iteritems():
    print key, value
    desired_capabilities['phantomjs.page.customHeaders.%s'%(key)] = value

#desired_capabilities['phantomjs.page.customHeaders.User-Agent'] ='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'

driver= webdriver.PhantomJS(executable_path='/tmp/phantomjs-2.1.1-linux-x86_64/bin/phantomjs',desired_capabilities=desired_capabilities)

driver.get("http://website.com")
print driver.get_cookies()

webdriver为phantomjs / ghostdriver代理

http://codego.net/549826/

pip install selenium

wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86\_64.tar.bz2

tar -jxvf phantomjs.tar.bz2

results matching ""

    No results matching ""