“权限被拒绝”错误废墟硒刮 [英] "Permission Denied" error ruins Selenium scraping

查看:198
本文介绍了“权限被拒绝”错误废墟硒刮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Selenium(Python Webdriver)来抓取一个网站。当我试图让它点击()一个选项,我得到一个权限被拒绝的错误。完整的堆栈跟踪:

  Traceback(最近调用的最后一个):
文件scrape.py,第19行,在< module>
subjectOptions [1] .click()
文件/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py,第45行,点击
self ._execute(Command.CLICK_ELEMENT)
文件/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py,行194,在_execute
返回self._parent.execute (command,params)
执行
的文件/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py,行153,self.error_handler.check_response(response)
文件/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py,第147行,在check_response
raise exception_class(message,screen,stacktrace)
selenium.common.exceptions.WebDriverException:消息:u'错误:调用方法时,拒绝< http:// localhost / scrape_test>获取属性HTMLDocument.compatMode的权限:[wdIMouse :: move]

这是导致问题的代码。我知道一个事实,即我试图点击的选项存在(基于 print ):



<$ p $从selenium导入webdriver
从selenium.common.exceptions中导入TimeoutException
从selenium.webdriver.support.ui导入WebDriverWait #available自2.4.0
导入时间

#创建FireFox驱动程序的新实例
驱动程序= webdriver.Firefox()

#转到本地版本的页面进行测试
driver.get(http:// localhost / scrape_test)

#通过ID查找选项,获取其选项
selectElement = driver.find_element_by_id(CLASS_SRCH_WRK2_SUBJECT $ 65 $)
subjectOptions = selectElement.find_elements_by_tag_name(option)

#单击所需的选项
subjectOptions [1] .click()

我在Mac OS X 10.7.2上使用Firefox 8.0.1

解决方案

看起来像是一个webdriver错误。最新日志条目,最后修改了一个selenium源代码文件:


这会导致权限错误,我仍然无法
减少:



错误:权限被拒绝

关于这个问题有一些讨论这里此处和< a href =http://code.google.com/p/selenium/issues/detail?id=2863 =noreferrer> here 。



根据讨论它应该适用于Firefox 7.另外,这个相关的问题意味着链接仍然被点击,尽管有错误,所以它可能在try /里面工作。


I've been scraping a website using Selenium (Python Webdriver). When I try to have it click() an option, I get a permission denied error. Full stack trace:

Traceback (most recent call last):
  File "scrape.py", line 19, in <module>
    subjectOptions[1].click()
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 45, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py", line 194, in _execute
    return self._parent.execute(command, params)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 153, in execute
    self.error_handler.check_response(response)
  File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 147, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u"'Error: Permission denied for <http://localhost/scrape_test> to get property HTMLDocument.compatMode' when calling method: [wdIMouse::move]"

Here is the code that causes the problem. I know for a fact that the option I'm trying to click exists (based on print):

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait #available since 2.4.0
import time

# Create a new instance of the FireFox driver
driver = webdriver.Firefox()

# go to the local version of the page for testing
driver.get("http://localhost/scrape_test")

# Find the select by ID, get its options
selectElement = driver.find_element_by_id("CLASS_SRCH_WRK2_SUBJECT$65$")
subjectOptions = selectElement.find_elements_by_tag_name("option")

# Click the desired option
subjectOptions[1].click()

I'm using Firefox 8.0.1 on Mac OS X 10.7.2

解决方案

Looks like it's a webdriver bug. The latest log entry from the programmer who last modified one of the selenium source code files says:

This leads to permissions errors, which I've still been unable to reduce:

Error: Permission denied for http://www.finn.no to get property HTMLDocument.compatMode' when calling method: [wdIMouse::move]

There is some discussion about the issue here, here and here.

According to the discussion it should work fine with Firefox 7. Also, this related issue implies that the link is still clicked in spite of the error, so it might work inside a try/except.

这篇关于“权限被拒绝”错误废墟硒刮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆