具体chromeDriver与Chrome对应版本号请查看这篇文件文章
from selenium import webdriver
path = "/path/to/chromedriver"# 注意这个路径需要时可执行路径(chmod 777 dir or 755 dir)
driver = webdriver.Chrome(executable_path=path, chrome_options=chrome_options)
def chrome_options(cls):
"""定制的options让他看起来更像一个webapp页面"""
mobile_emulation = { "deviceMetrics": {"width":375, "height": 667, "pixelRatio": 2.0}, "userAgent":"Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30" }
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
return chrome_options
@雾霾-2016-12-20 12:09:46