0
我绝对坚持这一个。我从网页上刮取餐厅网址,底部有一个按钮可显示更多餐馆。网站按钮代码如下(我相信):激活一个Python蜘蛛程序中的按钮
<div id="restsPages">
<a class="next" data-url="https://hungryhouse.co.uk/takeaways/aberdeen-bridge-of-dee-ab10">Show more</a>
<a class="back">Back to top</a>
</div>
这是“显示更多”按钮,我试图激活。 “data-url”中的url不会显示更多页面。
这一切似乎有点奇怪,如何激活python蜘蛛内的按钮?
我试图使用,使这项工作的代码是:
import scrapy
from hungryhouse.items import HungryhouseItem
from selenium import webdriver
class HungryhouseSpider(scrapy.Spider):
name = "hungryhouse"
allowed_domains = ["hungryhouse.co.uk"]
start_urls = ["https://hungryhouse.co.uk/takeaways/westhill-ab10",
]
def __init__(self):
self.driver = webdriver.Chrome()
def parse(self,response):
self.driver.get(response.url)
while True:
next =self.driver.find_element_by_xpath('//*[@id="restsPages"]/a[@class="next"]')
try:
next.click()
except:
break
self.driver.close()
.... rest of the code follows
我得到的错误是:“chromedriver”可执行文件需要在PATH
这已解决http://stackoverflow.com/questions/40699416/pressing-a-button-within-python-code参考答案http://stackoverflow.com/questions/29858752/error-message -chromedriver可执行的,需要将要可用,在最路径 – nevster