【发布时间】:2018-04-08 08:35:54
【问题描述】:
我正在尝试访问 JavaScript 动态站点的下一页。 http://msds.walmartstores.com/ 我一直试图激活以进入下一页的元素是:
<a href="#" class="next" data-action="next">›</a>
在这个网站上: http://msds.walmartstores.com/
可以在其中找到:
<div class="pagination" id="pagination" style="">
<a href="#" class="first" data-action="first">«</a>
<a href="#" class="previous" data-action="previous">‹</a>
<input type="text">
<a href="#" class="next" data-action="next">›</a>
<a href="#" class="last" data-action="last">»</a>
</div>
我能够获取我想要在此页面上抓取的所有 JavaScript 元素(PDF)。如何进入下一页?
我遇到的问题/尝试:
1
代码:
driver.find_element_by_class_name("next").click()
错误:
Traceback (most recent call last):
File "<stdin>", line 56, in <module>
File "<stdin>", line 50, in main
File "E:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 77, in click
self._execute(Command.CLICK_ELEMENT)
File "E:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 494, in _execute
return self._parent.execute(command, params)
File "E:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 236, in execute
self.error_handler.check_response(response)
File "E:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element i
s not clickable at point (251, 2173)
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cf
d9),platform=Windows NT 6.1.7601 SP1 x86_64)
shell returned 1
Hit any key to close this window...
2
代码:
driver.find_element_by_class_name("next").submit()
错误:
Traceback (most recent call last):
File "<stdin>", line 56, in <module>
File "<stdin>", line 50, in main
File "E:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 88, in submit
self._execute(Command.SUBMIT_ELEMENT)
File "E:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 494, in _execute return self._parent.execute(command, params)
File "E:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 236, in execute self.error_handler.check_response(response)
File "E:\Python27\lib\sitepackages\selenium\webdriver\remote\errorhandler.py", line 192,
in check_response raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element:
Element was not in a form, so could not submit.
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),
platform=Windows NT 6.1.7601 SP1 x86_64)
shell returned 1
Hit any key to close this window...
这是我打开网页的代码:
import time
from selenium import webdriver
import os
url = "http://msds.walmartstores.com/"
myfile = open("PDFLinks.txt", "w")
driver = webdriver.Chrome()
driver.get(url)
感谢您的帮助
【问题讨论】:
标签: python python-2.7 selenium web-scraping