我一直在使用Selenium(Python Webdriver)抓取网站。当我尝试将click()
作为选项时,我会收到权限被拒绝错误。完整堆栈跟踪:
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]"
以下是导致问题的代码。我知道我尝试点击的选项存在(基于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()
我在Mac OS X 10.7.2上使用Firefox 8.0.1
答案 0 :(得分:5)
看起来这是一个webdriver错误。最后修改了一个selenium源代码文件的程序员的最新log entry说:
这会导致权限错误,我仍然无法解决 降低:
错误:http://www.finn.no获取财产的权限被拒绝 HTMLDocument.compatMode'调用方法时:[wdIMouse :: move]
根据讨论,它应该可以与Firefox 7一起使用。此外,this related issue意味着尽管存在错误,仍然会点击链接,因此它可能在try / except中工作。
答案 1 :(得分:0)
暂时你可以克服here
的工作