Ejemplo n.º 1
0
def getWebDriver():
    caps = webdriver.DesiredCapabilities.PHANTOMJS

    # ua = random.choice(USER_AGENTS)
    ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36'

    headers = {
        'Accept': '*/*',
        # 'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'en-US,en,zh_CN;q=0.8',
        'Connection': 'keep-alive',
        'Cache-Control': 'max-age=0'
    }

    for key, value in headers.iteritems():
        caps['phantomjs.page.customHeaders.{}'.format(key)] = value

    # caps["phantomjs.page.settings.userAgent"] = ua
    # ranBrow = random.choice(phantomBrowserNames)
    # caps["browserName"] = ranBrow
    # caps['platform'] = ua
    # caps['version'] =

    driver = webdriver.PhantomJS(executable_path=phantomPath,
                                 desired_capabilities=caps)
    # driver = webdriver.Chrome(executable_path='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome')

    driver.set_page_load_timeout(30)
Ejemplo n.º 2
0
 def __init__(self):
     self.driver = webdriver.PhantomJS(executable_path=r'C:\用户\10359\local\bin\phantomjs.exe')
#!/usr/bin/python2.7
# -*- coding:utf-8 -*-

# Author: NetworkRanger
# Date: 2019/1/28 7:32 PM

from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.phantomjs import webdriver

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
    "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36"
)
driver = webdriver.PhantomJS()  #desired_capabilities=dcap)
driver.get("http://www.google.com")
driver.quit()