我正在尝试使用Selenium + JavaScript + XPath从网页中读取一些值。
这是我的代码:
print browser.execute_script("window.document.evaluate('/html/body/div[5]/div[7]/div/table/tbody/tr/td[3]', document, null, XPathResult.ANY_TYPE, null).iterateNext().textContent;")
不幸的是,每次运行它都会产生错误,是否有任何方法可以使其正常工作?
这是追溯:
Traceback (most recent call last): File "gains.py", line 50, in print browser.execute_script("window.document.evaluate('/html/body/div[5]/div[7]/div/table/tbody/tr/td[3]', document, null, XPathResult.ANY_TYPE, null).iterateNext().textContent") File "/usr/local/lib/python2.6/dist-packages/selenium-2.21.2-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 385, in execute_script {'script': script, 'args':converted_args})['value'] File "/usr/local/lib/python2.6/dist-packages/selenium-2.21.2-py2.6.egg/selenium/webdriver/remote/webdriver.py", line 153, in execute self.error_handler.check_response(response) File "/usr/local/lib/python2.6/dist-packages/selenium-2.21.2-py2.6.egg/selenium/webdriver/remote/errorhandler.py", line 147, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: ''