下载地址:f6u7
安装指令:
chmod 755 /opt/phantomjs-2.1.1-linux-x86_64/bin/phantimjs
配置:
from fake_useragent import UserAgent
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
USER_AGENT_JSON_PATH = '/opt/DHS_Digikey/ua.json'
PHANTOMJS_PATH = '/opt/DHS_Digikey/phantomjs-2.1.1-linux-x86_64/bin/phantomjs'
dcap = dict(DesiredCapabilities.PHANTOMJS)
def get_dirver(self, re_state):
if re_state:
# proxy = Proxy({'proxyType': ProxyType.MANUAL, 'httpProxy': '180.122.63.242:4257'})
# proxy.add_to_capabilities(dcap)
dcap['phantomjs.page.customHeaders.Referer'] = 'https://www.lubaogui.com'
dcap['browserName'] = 'chrome'
dcap['phantomjs.page.settings.loadImages'] = False
dcap['phantomjs.page.settings.loadImages'] = False
dcap['phantomjs.page.settings.resourceTimeout'] = 100
dcap['phantomjs.page.settings.User-Agent'] = UserAgent(path=USER_AGENT_JSON_PATH).random
for key, value in self.headers.items():
dcap['phantomjs.page.settings.{}'.format(key)] = value
service_args = []
service_args.append('--load-images=no') ##关闭图片加载
service_args.append('--disk-cache=yes') ##开启缓存
service_args.append('--ignore-ssl-errors=true') ##忽略https错误
self.driver = webdriver.PhantomJS(desired_capabilities=dcap, executable_path=PHANTOMJS_PATH, service_args=service_args)
self.driver.implicitly_wait(10) ##设置超时时间
self.driver.set_page_load_timeout(120) ##设置页面超时时间
self.driver.set_script_timeout(120)