selenium_指定chromedriver路径

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_29726869/article/details/82179332

selenium_指定chromedriver路径

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

猜你喜欢

转载自blog.csdn.net/qq_29726869/article/details/82179332