【发布时间】:2020-06-03 18:09:11
【问题描述】:
我正在尝试在 Google 上抓取一些图片。我找到了这段代码,但它不起作用。 我该如何解决这个错误??
from urllib.request import urlopen
from urllib.request import urlretrieve
from urllib.parse import quote_plus
from bs4 import BeautifulSoup
from selenium import webdriver
search= input('검색어:')
url = f'https://www.google.com/search?q={quote_plus(search)}&source=inms&tbm=isch&sa=X&ved=2haUKEwid64aF87LoAhUafd4KHcEtBZEQ_AUoAXoECBgQAw&biw=1536&bih=754'
driver = webdriver.Chrome()
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html)
img = soup.select('.rg_i.Q4LuWd.tx8vtf')
n = 1
imgurl = []
for i in img:
try:
imgurl.append(i.attrs['src'])
except KeyError:
imgurl.append(i.attrs["data-src"])
for i in imgurl:
urlretrieve(i,"크롤링 사진/"+ search + ".jpg")
n +=1
print(imgurl)
driver.close()
(검색어在韩语中的意思是“搜索词”。)
错误信息
Traceback (most recent call last):
File "C:\Users\u\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\u\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\u\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] 지정된 파일을 찾을 수 없습니다
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "yt.py", line 10, in <module>
driver = webdriver.Chrome()
File "C:\Users\u\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__ self.service.start()
File "C:\Users\u\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
感谢您的帮助。
【问题讨论】:
-
我认为这是第二个问题:“selenium.common.exceptions.WebDriverException: Message: 'chromedriver' 可执行文件需要在 PATH 中。请参阅sites.google.com/a/chromium.org/chromedriver/home"
标签: python python-3.x selenium selenium-webdriver