【问题标题】:I am trying to Scrape reviews from Amazon using Python 3.x but getting nothing我正在尝试使用 Python 3.x 从亚马逊上抓取评论,但一无所获
【发布时间】:2016-06-30 23:15:44
【问题描述】:

我正在尝试抓取来自亚马逊的所有评论。当我在下面运行我的代码时,它返回空列表而没有任何错误。我不知道为什么。你能帮帮我吗?

from __future__ import unicode_literals

import requests
from scrapy.selector import Selector

def fetch_page(url):
    r = requests.get(url)
    return r.text 

def  review_positive(url):
    #html = fetch_page(url)
    sel = Selector(text = url)
    review =  sel.css(' .a-section review').extract()
    return review


print (review_positive('https://www.amazon.com/Apple-iPhone-Unlocked-GB-Packaging/product-reviews/B01DAJT1AW/ref=cm_cr_arp_d_viewpnt_lft?ie=UTF8&showViewpoints=1&sortBy=helpful&filterByStar=positive&pageNumber=1'))

【问题讨论】:

    标签: python scrapy amazon screen-scraping review


    【解决方案1】:

    您的 CSS 选择器中的类之间不应有空格。相反,使用. 来分隔类:

    .css('.a-section.review').extract()
    

    一旦你解决了这个问题,你的选择器就会正常工作:

    In [6]: rev = response.css('.a-section.review').extract()
    
    In [7]: len(rev)
    Out[7]: 10
    
    In [8]: rev = response.css('.a-section review').extract()
    
    In [9]: len(rev)
    Out[9]: 0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      • 2013-07-22
      • 2020-01-26
      • 2017-03-11
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      相关资源
      最近更新 更多