Selenium错误消息(nvalidArgumentException)
当我尝试使用Selenium时,我得到一个错误,如下所示:Selenium错误消息(nvalidArgumentException),selenium,google-chrome,web-scraping,selenium-chromedriver,invalid-argument,Selenium,Google Chrome,Web Scraping,Selenium Chromedriver,Invalid Argument,当我尝试使用Selenium时,我得到一个错误,如下所示: nvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir 我的代码: driver = webdriver.Chrome('chrome
nvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
我的代码:
driver = webdriver.Chrome('chromedriver\chromedriver.exe')
# request url
driver.get('https://jamalon.com/ar/best-seller-books-2019')
#give it some time
sleep(2)
## retrive , download html page
html = driver.page_source
#close
driver.close()
我尝试在此处执行相同的解决方案,但我得到相同的错误:(
如果您正在使用Pycharm,请首先将chromedriver.exe保存在当前python文件所在的位置 然后使用以下代码:
from selenium import webdriver
import time
driver = webdriver.Chrome()
# request url
driver.get('https://jamalon.com/ar/best-seller-books-2019')
#give it some time
time.sleep(2)
## retrive , download html page
html = driver.page_source
print(html)
#close
driver.close()
输出:
尝试为您的chromedriver.exei do.提供绝对路径。无任何更改可能重复。检查此答案-谢谢您,Amar,我使用Jupyter笔记本,我尝试了cod,但我再次遇到相同错误,将chromedriver路径包含在webdriver.Chrome(“)函数中。只需保持路径格式如下:-driver=webdriver.Chrome(可执行文件\u path=r'C:\Users\GSC-30431\AppData\Local\Programs\Python37-32\Lib\site packages\selenium\webdriver\chrome\chromedriver.exe)或将chromedriver文件与jupyter笔记本文件一起保存在同一路径中。并且不要将路径包含在文件名下,例如-driver=webdriver.chrome()。这也会起作用。我将其更改为:driver=webdriver.Chrome(可执行文件\u path=r'C:\Users\LAM\Desktop\DSI\project3\project-3\chromedriver\chromedriver.exe')…页面将打开,但出现错误。。