目录
'chromedriver' executable needs to be in PATH
selenium.common.exceptions.WebDriverException: Message: unknown Error: cannot find Chrome binary
selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreat
'chromedriver' executable needs to be in PATH
selenium.common.exceptions.WebDriverException: Message: unknown Error: cannot find Chrome binary
selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.executionContextCreat
上述问题要么是Chromedriver版本和谷歌浏览器版本没对上,要么是配置有问题
1.下载Chromedriver,注意自己谷歌浏览器的版本和Chromedriver的版本必须对应。对应表请自行搜索。
2.将chromedriver.exe拷贝至谷歌浏览器目录(如 C:\Program Files\Google\Chrome\Application)以及python根目录。对于用anaconda的拷贝至envs里你准备使用Selenium的环境的根目录下。
3.将谷歌浏览器环境变量添加到path。 如果这里搞不定的在代码中指定chrome.exe绝对路径也可以。
option = webdriver.ChromeOptions()
option.binary_location=r'xxx\chrome.exe' #xxx请自行替换
driver = webdriver.Chrome()
设置js执行超时时间
driver.set_script_timeout(xxx)
读取js文件和执行js代码
首先这个js文件要存在
js = open("jquery-3.4.1.min.js", "r").read()
driver.execute_script(js)
执行js代码,类似
比如form = ''' var fd = new window.FormData(); fd.append......'''
driver.execute_script(form)