我已经下载了适用于 Chrome 的最新版本 chromedriver 版本 125.0.6422.61(64 位)。我的目录中有该文件,系统环境中有路径 (C:\Users\USER PC\Documents\Flatiron\Web_Scraping),但是当我在脚本中运行此行时
# Initializing the webdriver
options = webdriver.ChromeOptions()
# Change the path to where chromedriver is in your home folder.
driver = webdriver.Chrome(executable_path="/Users/USER PC/Documents/Flatiron/Web_Scraping", options=options)
driver.set_window_size(1120, 1000)
我收到权限错误
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
WebDriverException Traceback (most recent call last)
Cell In[33], line 2
1 #This line will open a new chrome window and start the scraping.
----> 2 df = get_jobs("data scientist", 5, False)
3 df
Cell In[31], line 13, in get_jobs(keyword, num_jobs, verbose)
6 options = webdriver.ChromeOptions()
8 #Uncomment the line below if you'd like to scrape without a new Chrome window every time.
9 #options.add_argument('headless')
10
11 #Change the path to where chromedriver is in your home folder.
---> 13 driver = webdriver.Chrome(executable_path="/Users/USER PC/Documents/Flatiron/Web_Scraping", options=options)
14 driver.set_window_size(1120, 1000)
…
WebDriverException: Message: 'Web_Scraping' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我更改了可执行路径并设置了页面加载的超时值,如下所示
# Change the path to where chromedriver is in your home folder.
driver = webdriver.Chrome(executable_path=r'C:/Users/USER PC/Documents/Flatiron/Web_Scraping/chromedriver.exe', options=options)
driver.set_window_size(1120, 1000)
driver.set_page_load_timeout(30) # Set the timeout value for page load
driver.implicitly_wait(10) # Set implicit wait time for finding elements
这会返回此值错误
ValueError: Timeout value connect was <object object at 0x000001E756FC01F0>, but it must be an int, float or None.
我需要做什么才能同时修复权限和超时错误?
我为你找到了解决方案 我只是构建一个简单的测试用例来打开 google 网站,它在 2 秒内自动关闭 我浪费了 2 天的时间来找出问题所在。 最后我将浏览器从 chrome 切换到 firefox,现在它运行得非常好...... 立即切换浏览器