2016-11-12 44 views
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

+0

這已解決http://stackoverflow.com/questions/40699416/pressing-a-button-within-python-code參考答案http://stackoverflow.com/questions/29858752/error-message -chromedriver可執行的,需要將要可用,在最路徑 – nevster

回答