1
我一時間知道,您需要使用像硒這樣的webtoolkits來自動化刮擦。如何將硒與scrapy一起使用來實現過程自動化?
我怎樣才能點擊谷歌Play商店的下一個按鈕,以刮擦我的大學目的評論!
import scrapy
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.selector import Selector
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from urlparse import urljoin
from selenium import webdriver
import time
class Product(scrapy.Item):
title = scrapy.Field()
class FooSpider(CrawlSpider):
name = 'foo'
start_urls = ["https://play.google.com/store/apps/details?id=com.gaana&hl=en"]
def __init__(self, *args, **kwargs):
super(FooSpider, self).__init__(*args, **kwargs)
self.download_delay = 0.25
self.browser = webdriver.Chrome(executable_path="C:\chrm\chromedriver.exe")
self.browser.implicitly_wait(60) #
def parse(self,response):
self.browser.get(response.url)
sites = response.xpath('//div[@class="single-review"]/div[@class="review-header"]')
items = []
for i in range(0,200):
time.sleep(20)
button = self.browser.find_element_by_xpath("/html/body/div[4]/div[6]/div[1]/div[2]/div[2]/div[1]/div[2]/button[1]/div[2]/div/div")
button.click()
self.browser.implicitly_wait(30)
for site in sites:
item = Product()
item['title'] = site.xpath('.//div[@class="review-info"]/span[@class="author-name"]/a/text()').extract()
yield item
我已更新我的代碼,它只是一次又一次地給我重複40個項目。我的for循環出了什麼問題?
看來,它也被更新不傳遞到的XPath這就是爲什麼它與同40項
它仍然沒有在瀏覽器中加載url –
瀏覽器打開,但沒有輸入url –
嘗試'webdriver.Chrome()'而不是'webdriver.Firefox()'。 Firefox也不適用於我的情況。 – Timofey