我知道这已经有很多话题了,但是我已经遍历了所有话题,这是我第三天试图突破并且没有任何改进。情况如下:
我正在尝试使用此https://github.com/tejavoo/GooglePlayReviewScraper/blob/master/scraper.py来为我的研究创建一个Google Play评论刮板,但是继续收到以下错误:
Conda3 / Python38 / Windows10 / Spyder 4.0.1
我已经确保chromedriver在PATH中,并且已将其与spyder和python一起作为所有权限。我还确保它是与我的谷歌浏览器匹配的正确版本。
我已经下载了chromedriver,将其解压缩到我正在使用的文件夹中。
在最近更新到spyder 4之前,我也没有权限错误(Winerror 5)。
请,我想念什么?
chromedriver = "C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe"
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600') # optional
driver = webdriver.Chrome(executable_path = chromedriver, chrome_options = options)
错误
Traceback (most recent call last):
File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 104, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)
File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\subprocess.py", line 1207, in _execute_child
startupinfo)
*PermissionError: [WinError 5] Access is denied*
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\james\Downloads\ML\New folder\PlayReviews.py", line 37, in <module>
driver = webdriver.Chrome(executable_path = chromedriver, chrome_options = options)
File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
os.path.basename(self.path), self.start_error_message)
WebDriverException: 'chromedriver.exe' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
如果我更改代码并将''放在chromedriver周围
chromedriver = ("C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe")
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600') # optional
driver = webdriver.Chrome(executable_path= 'chromedriver', chrome_options = 'options')
我明白了
runcell(0, 'C:/Users/james/Downloads/ML/New folder/PlayReviews.py')
C:\Users\james\Downloads\ML\New folder\PlayReviews.py:37: DeprecationWarning: use options instead of chrome_options
driver = webdriver.Chrome(executable_path= 'chromedriver', chrome_options = 'options')
Traceback (most recent call last):
File "C:\Users\james\Downloads\ML\New folder\PlayReviews.py", line 37, in <module>
driver = webdriver.Chrome(executable_path= 'chromedriver', chrome_options = 'options')
File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 64, in __init__
desired_capabilities = options.to_capabilities()
AttributeError: 'str' object has no attribute 'to_capabilities'
然后打开一个webdriver.py页面
非常感谢您的帮助!
干杯:)
更新
我尝试了提到的原始字符串的想法
chromedriver = "C:/Users/james/Downloads/ML/New folder/PlayReviews.py"
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600') # optional
driver = webdriver.Chrome(executable_path = r'C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe', chrome_options='options')
似乎通过了吗?到目前为止,我一直在处理此错误:
runcell(0, 'C:/Users/james/Downloads/ML/New folder/PlayReviews.py')
C:\Users\james\Downloads\ML\New folder\PlayReviews.py:39: DeprecationWarning: use options instead of chrome_options
driver = webdriver.Chrome(executable_path = r'C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe', chrome_options='options')
Traceback (most recent call last):
File "C:\Users\james\Downloads\ML\New folder\PlayReviews.py", line 39, in <module>
driver = webdriver.Chrome(executable_path = r'C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe', chrome_options='options')
File "C:\Users\james\.conda\envs\spyder-4.0.0_1\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 64, in __init__
desired_capabilities = options.to_capabilities()
AttributeError: 'str' object has no attribute 'to_capabilities'
但是,此错误实际上来自webdriver.py的第64行,该行由于运行前者而打开
if chrome_options:
warnings.warn('use options instead of chrome_options',
DeprecationWarning, stacklevel=2)
options = chrome_options
if options is None:
# desired_capabilities stays as passed in
if desired_capabilities is None:
desired_capabilities = self.create_options().to_capabilities()
else:
if desired_capabilities is None:
desired_capabilities = options.to_capabilities()
else:
desired_capabilities.update(options.to_capabilities())
答案 0 :(得分:1)
这是我登录并查看此处新问题的小脚本的一部分。它在C#中的另一个库中,但也许仍然有用,它将帮助您发现问题。无论如何,下面的代码都希望对您有所帮助。
您唯一不需要做的就是在ChromeOptions上设置BinaryLocation,然后在运行时发现驱动程序目录。
此外,有时此类错误消息完全是由他们所说的错误引起的。也许为了运行selenium驱动程序,它可能需要更多提升的Windows权限,例如,当您右键单击并说以管理员身份在程序上运行时,有时会如此。您是否尝试过以管理员身份运行要运行python脚本的终端/命令行?
ChromeOptions options = new ChromeOptions();
options.BinaryLocation = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
using (IWebDriver driver = new ChromeDriver(GetChromeDriverDirectory(), options))
{
driver.NavigateToUrl("https://stackoverflow.com/questions/tagged?sort=Newest&filters=NoAnswers&tagMode=Watched");
}
// Here is the method I use to get the Chrome driver directory.
private static string GetChromeDriverDirectory() => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
答案 1 :(得分:1)
当可执行文件路径不是原始字符串时,我看到了类似的权限错误。您是否尝试过像这样格式化它?
driver = webdriver.Chrome(executable_path = r'C:\\Users\\james\\Downloads\\ML\\New folder\\chromedriver.exe', chrome_options = options)
答案 2 :(得分:0)
您需要注意一些事项:
r
开关。chrome_options
,相反,您需要使用options
。您的有效代码块将是:
options = webdriver.ChromeOptions()
options.headless = True
# previously: options.set_headless(headless=True)
# long ago: options.add_argument('--headless')
options.add_argument('--window-size=1200x600')
driver = webdriver.Chrome(executable_path = r'C:\Users\james\Downloads\ML\New folder\chromedriver.exe', options='options')
您可以在以下位置找到一些相关的讨论
答案 3 :(得分:0)
我终于设法弄清楚哪里出了问题。
虽然我拥有PATH且一切正确-Chromdriver.exe文件不在我的Python / scripts文件夹中。
在此设置好之后,重新放置PATH,一切正常! :)