Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我试图使用Python3.x从Amazon上获取评论,但一无所获_Python_Scrapy_Amazon_Screen Scraping_Review - Fatal编程技术网

我试图使用Python3.x从Amazon上获取评论,但一无所获

我试图使用Python3.x从Amazon上获取评论,但一无所获,python,scrapy,amazon,screen-scraping,review,Python,Scrapy,Amazon,Screen Scraping,Review,我正试图从亚马逊获取所有评论。当我运行下面的代码时,它返回空列表,没有任何错误。我不明白为什么。你能帮帮我吗 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): #h

我正试图从亚马逊获取所有评论。当我运行下面的代码时,它返回空列表,没有任何错误。我不明白为什么。你能帮帮我吗

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'))

在类之间的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