我正在使用Selenium和Scrapy要从动态网站中删除内容。我是新手到Selenium。我从here中提取酒单。该网站有一个show more
按钮,点击后会显示更多葡萄酒列表。至于现在,我只能点击一下按钮并提取酒单。但我需要每次点击按钮,直到show more
按钮不显示。任何对此的帮助将非常感激。这里是我的代码到目前为止:Selenium检查元素是否退出并单击
# -*- coding: utf-8 -*-
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors import LinkExtractor
from selenium import webdriver
from scrapy.selector import Selector
import time
class WineSpider(CrawlSpider):
name = "wspider"
allowed_domains = ["vivino.com"]
start_urls = ["http://www.vivino.com/wineries/francis-ford-coppola/"] #hloru
def __init__(self):
self.driver = webdriver.Firefox()
def parse(self,response):
sel = Selector(self.driver.get(response.url))
self.driver.get(response.url)
links = []
time.sleep(5)
#this is for selecting the show more button
click = self.driver.find_elements_by_xpath("//*[@id='btn-more-wines']")
click[0].click()
time.sleep(5)
wines = self.driver.find_elements_by_xpath('//a[@class = "link-muted"]')
for w in wines:
links.append(w.get_attribute("href"))
print len(links)
self.driver.close()
任何帮助将是非常有用的。