From selenium import Webdriver
From selenium.webdriver.common.desired_capabilities import desiredcapabilities
Dcap = Dict (DESIREDCAPABILITIES.PHANTOMJS)
#dcap ["phantomjs.page.settings.userAgent"] = ("mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/45.0.2454.101 safari/537.36 QIHU 360SE ")
dcap["phantomjs.page.settings.userAgent"] = (Random.choice (agents))
dcap["phantomjs.page.settings.loadImages"] = False
#dcap ["phantomjs.page.settings.disk-cache"] = True
dcap["Phantomjs.page.customHeaders.Cookie"] = ' xxxxxxxxxx '
#driver = Webdriver. Phantomjs (executable_path= ' C:\\python27\\phantomjs.exe ', service_args=['--load-images=no '],desired_capabilities =DCAP) #或者把phantomjs放在任何一个是环境变量文件夹的里面.
Driver = Webdriver. Phantomjs (executable_path= '/home/yangdefeng/downloads/phantomjs-2.1.1-linux-x86_64/bin/phantomjs ', Service_args =['--load-images=no '],desired_capabilities=dcap) #linux版本的需要修改phantomjs文件的权限, chmod u+x Phantomjs, Otherwise the error peimission delined
PHANTOMJS Rendering Web pages