Python WebDriverException:消息:';chromedriver.exe';可执行文件需要在路径中。请看https://sites.google.com/a/chromium.org/chromedriver/home
对于以下代码:Python WebDriverException:消息:';chromedriver.exe';可执行文件需要在路径中。请看https://sites.google.com/a/chromium.org/chromedriver/home,python,selenium,selenium-webdriver,selenium-chromedriver,jupyter,Python,Selenium,Selenium Webdriver,Selenium Chromedriver,Jupyter,对于以下代码: ################################# # Simple-Instagram-Scraper v1.0.3 # Release: 10.11.2020 # GitHub: do-me ################################# from selenium import webdriver from bs4 import BeautifulSoup as bs import time import re from urllib.
#################################
# Simple-Instagram-Scraper v1.0.3
# Release: 10.11.2020
# GitHub: do-me
#################################
from selenium import webdriver
from bs4 import BeautifulSoup as bs
import time
import re
from urllib.request import urlopen
import json
from pandas.io.json import json_normalize
import pandas as pd, numpy as np
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import random
import string
from time import gmtime, strftime
import os
option = webdriver.ChromeOptions()
chrome_prefs = {}
option.experimental_options["prefs"] = chrome_prefs
chrome_prefs["profile.default_content_settings"] = {"images": 2}
chrome_prefs["profile.managed_default_content_settings"] = {"images": 2}
# Parameters
#---------------------------------------------------------------
# CRUCIAL PARAMS
# directory to chromedriver or geckodriver, find chromedriver here: https://chromedriver.chromium.org/
browser = webdriver.Chrome("yourpath/chromedriver.exe", options=option)
# user credentials
username = "username"
userpassword = "userpassword"
# which page?
pagetoscrape = "https://www.instagram.com/explore/locations/118546/thessaloniki/" # either hashtag, location id or user account possible
# pagetoscrape = "https://www.instagram.com/explore/tags/berlin/"
#---------------------------------------------------------------
# OPTIONAL PARAMS
# maximum posts to scrape
maxiter = 10000
# filename for output csv
out_csv = "-".join(pagetoscrape.split("/")[-3:])[:-1] + ".csv" # i.e.'118546-thessaloniki' for locations or tags-berlin for hashtags
# quite crucial but subject to trial and error due to unknown Instagram blocking policy: breaks
# set a random break duration for every iteration after opening one post and before going to the next one
short_pauseduration_min = 2 # seconds
short_pauseduration_max = 2.7 # seconds
# set a random break duration for longer breaks...
long_pauseduration_min = 4.8 # seconds
long_pauseduration_max = 10.5 # seconds
# ...for the following random iterations (number of iterations = index of scraped posts)
pauselist = random.sample(range(10, 10000), 400) # between 10 and 10000 generate list of 500 values # randomList.sort() for sorting
pauselist.append([x + int(random.uniform(1,10)) for x in np.arange(20, 10000, 50).tolist()]) # just to make sure: add list with values every 51th to 60th iteration
#---------------------------------------------------------------
# ADVANCED PARAMS
# uncomment for saving in a folder called "data" you created before manually
# if os.getcwd().split("\\")[-1] != "data": # if you changed working dir already for some reason
# os.chdir(r"data")
我得到以下错误:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/service.py in start(self)
75 stderr=self.log_file,
---> 76 stdin=PIPE)
77 except TypeError:
~/anaconda3/lib/python3.7/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
799 errread, errwrite,
--> 800 restore_signals, start_new_session)
801 except:
~/anaconda3/lib/python3.7/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
1550 err_msg += ': ' + repr(err_filename)
-> 1551 raise child_exception_type(errno_num, err_msg, err_filename)
1552 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'yourpath/chromedriver.exe': 'yourpath/chromedriver.exe'
During handling of the above exception, another exception occurred:
WebDriverException Traceback (most recent call last)
<ipython-input-3-943542c00cca> in <module>
34
35 # directory to chromedriver or geckodriver, find chromedriver here: https://chromedriver.chromium.org/
---> 36 browser = webdriver.Chrome("yourpath/chromedriver.exe", options=option)
37
38 # user credentials
~/anaconda3/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, keep_alive)
71 service_args=service_args,
72 log_path=service_log_path)
---> 73 self.service.start()
74
75 try:
~/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/service.py in start(self)
81 raise WebDriverException(
82 "'%s' executable needs to be in PATH. %s" % (
---> 83 os.path.basename(self.path), self.start_error_message)
84 )
85 elif err.errno == errno.EACCES:
WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
---------------------------------------------------------------------------
FileNotFoundError回溯(最近一次调用上次)
开始时使用~/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/service.py(self)
75 stderr=self.log_文件,
--->76标准偏差=管道)
77除类型错误外:
~/anaconda3/lib/python3.7/subprocess.py in_uuuuinit_uuuu(self、args、bufsize、executable、stdin、stdout、stderr、preexec_fn、close_fds、shell、cwd、env、universal_u新行、startupinfo、creationflags、restore_u信号、start_新会话、pass_fds、编码、错误、文本)
799错读,错写,
-->800恢复信号,启动新会话)
801除:
~/anaconda3/lib/python3.7/subprocess.py in_execute_child(self、args、execute、preexec_fn、close_fds、pass_fds、cwd、env、startupinfo、creationflags、shell、p2cread、p2cwrite、c2pwrite、errread、errwrite、restore_信号、start_new_会话)
1550 err_msg+=':'+repr(err_文件名)
->1551引发子项异常类型(errno\u num、err\u msg、err\u filename)
1552引发子项异常类型(错误消息)
FileNotFoundError:[Errno 2]没有这样的文件或目录:“yourpath/chromedriver.exe”:“yourpath/chromedriver.exe”
在处理上述异常期间,发生了另一个异常:
WebDriverException回溯(最近一次调用上次)
在里面
34
35#chromedriver或geckodriver的目录,请在此处找到chromedriver:https://chromedriver.chromium.org/
--->36 browser=webdriver.Chrome(“yourpath/chromedriver.exe”,options=option)
37
38#用户凭证
~/anaconda3/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py in\uuuuuuu init\uuuuuuuu(self、可执行路径、端口、选项、服务参数、所需的功能、服务日志路径、chrome\u选项、保持活动状态)
71服务参数=服务参数,
72日志路径=服务日志路径)
--->73自助服务启动()
74
75尝试:
开始时使用~/anaconda3/lib/python3.7/site-packages/selenium/webdriver/common/service.py(self)
81提出WebDriverException(
82“'%s'可执行文件需要位于路径中。%s”%(
--->83 os.path.basename(self.path)、self.start\u错误消息)
84 )
85 elif err.errno==errno.EACCES:
WebDriverException:消息:“chromedriver.exe”可执行文件需要位于路径中。请看https://sites.google.com/a/chromium.org/chromedriver/home
这里有两个问题:
它不需要在你的道路上。如果你注意到了,它实际上告诉你,它没有在你提供的路径上找到chromedriver,因为那里没有文件。给它一个工作路径,你就没事了。谢谢,这就是可执行文件所在的位置~/Downloads/chromedriver\u linux64.zip/chromedriver/chromedriver\u linux64/chromedriver不知道该怎么处理它。你能把你的答案扩大2吗。帮我想想怎么处理这个?~在这种情况下不能作为路径字符串。从当前目录中给出绝对路径(以/)或相对路径我应该如何做?你能说得更具体些吗
给出当前目录的绝对路径(以/)或相对路径
以下是一个示例。如果您在windows上,则绝对路径类似于“C:/Users/username/Downloads/…/chromedriver.exe”
。在Linux上,它看起来像“/usr/Downloads/…/chromedriver”
。我不确定我还能帮上多少忙,你可以发现你也在程序中传递一个路径作为参数,因此将它添加到系统路径会被覆盖谢谢这就是可执行文件的位置~/Downloads/chromedriver\u linux64.zip/chromedriver/chromedriver\u linux64/chromedriver不确定如何处理它。你能把你的答案扩大2吗。帮我想想怎么处理这个?~在这种情况下不能作为路径字符串。从当前目录中给出绝对路径(以/)或相对路径我应该如何做?你能说得更具体些吗给出当前目录的绝对路径(以/)或相对路径
以下是一个示例。如果您在windows上,则绝对路径类似于“C:/Users/username/Downloads/…/chromedriver.exe”
。在Linux上,它看起来像“/usr/Downloads/…/chromedriver”
。我不确定我还能帮上多少忙,你可以发现你在程序中也把一个路径作为参数传递给它,所以把它添加到你的系统路径会被覆盖