【发布时间】:2015-07-02 20:50:31
【问题描述】:
我写这个蜘蛛是为了从 google play 中抓取应用程序的评论。我在这方面取得了部分成功。我只能提取姓名、日期和评论。
我的查询: 1.如何获得所有评论,因为我只得到 41。 2.如何从div中获取评分?
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
class CompItem(scrapy.Item):
rating = scrapy.Field()
data = scrapy.Field()
name = scrapy.Field()
date = scrapy.Field()
class criticspider(CrawlSpider):
name = "gaana"
allowed_domains = ["play.google.com"]
start_urls = ["https://play.google.com/store/apps/details?id=com.gaana&hl=en"]
# rules = (
# Rule(
# SgmlLinkExtractor(allow=('search=jabong&page=1/+',)),
# callback="parse_start_url",
# follow=True),
# )
def parse(self, response):
sites = response.xpath('//div[@class="single-review"]')
items = []
for site in sites:
item = CompItem()
item['data'] = site.xpath('.//div[@class="review-body"]/text()').extract()
item['name'] = site.xpath('.//div/div/span[@class="author-name"]/a/text()').extract()[0]
item['date'] = site.xpath('.//span[@class="review-date"]/text()').extract()[0]
item['rating'] = site.xpath('div[@class="review-info-star-rating"]/aria-label/text()').extract()
items.append(item)
return items
【问题讨论】:
-
@JonathonReinhart 抱歉,我对此一无所知!
-
从技术上讲,如果您正在访问该网站,则您已经同意他们的服务条款。
-
你永远不知道一个好的数据能做什么。 #calmdownbro
-
我认为有很多企业建立在此之上。查看 Sensor Tower、Mobile Action 等聚合网站……您认为他们如何获取数据?他们一定只是在抓取网站。
-
@user1406716 准确
标签: python xpath web-scraping google-play scrapy