Phantomjs设置浏览器useragent的方式

Selenium中使用PhantomJS,设置User-Agent的方法。

默认情况下,是没有自动设置User-Agent的;设置PhantomJS的user-agent

 

def __init__(self):
cap = webdriver.DesiredCapabilities.PHANTOMJS
cap["phantomjs.page.settings.resourceTimeout"] = 1000
cap["phantomjs.page.settings.loadImages"] = True
cap["phantomjs.page.settings.disk-cache"] = True

cap[
"phantomjs.page.settings.userAgent"] = "Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0",

cap[
"phantomjs.page.customHeaders.User-Agent"] = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0',
self.driver = webdriver.PhantomJS(desired_capabilities=cap)

转载于:https://www.cnblogs.com/fly-kaka/p/6137255.html

你可能感兴趣的:(Phantomjs设置浏览器useragent的方式)