设置phantomjs User Agent字符串

・1 分钟阅读

为phantomjs驱动程序设置User Agent

 

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
 "(KHTML, like Gecko) Chrome/15.0.87"
)
driver = webdriver.PhantomJS(desired_capabilities=dcap)
Xajhqffl profile image