【问题标题】:How to use scrapy to scrape google play reviews of applications?如何使用 scrapy 抓取应用程序的 google play 评论?
【发布时间】: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


【解决方案1】:

你可以试试这个:

item['rating'] = site.xpath('.//div[@class="tiny-star star-rating-non-editable-container"]/@aria-label').extract()

【讨论】:

    【解决方案2】:

    你有

     item['rating'] = site.xpath('div[@class="review-info-star-rating"]/aria-label/text()').extract()
    

    不应该是这样的:

    item['rating'] = site.xpath('.//div[@class="review-info-star-rating"]/aria-label/text()').extract()
    

    ??不知道它是否会起作用,但请尝试:)

    【讨论】:

    • 你到底改变了什么?
    • 在 div 前添加了“.//” :)
    猜你喜欢
    • 2020-08-01
    • 2021-02-12
    • 2020-02-23
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多