无法使用BeautifulSoap报废内容

问题描述:

我是网站scraping,使用PythonBeautifulSoap无法使用BeautifulSoap报废内容

我得刮这个页面。

http://www.starwoodhotels.com//sheraton/property/reviews/index.html?language=en_US&propertyID=115

在此页面中,我已经刮掉酒店的地址成功,但是我不能刮网友评论部分

这里是我的代码

hotel_link = "http://www.starwoodhotels.com//sheraton/property/reviews/index.html?language=en_US&propertyID=115" 

hotel_page_html = requests.get(hotel_link,headers = header).text 
hotel_page_soup = BeautifulSoup(hotel_page_html) 

for hotel_address in hotel_page_soup.select("div#propertyAddressContainer ul#propertyAddress"): 
    print("Address: "+hotel_address.select("li")[0].text) 

print(hotel_page_soup.select("div.BVRRRatingNormalOutOf")) 

,你可以看到,使用CSS选择器div#propertyAddressContainer ul#propertyAddress,我已经得到了地址,但无法抓取User Reviews部分。

我在页面加载时检查了Console,但没有看到用户评论通过AJAX调用加载的任何内容。

那么如何刮评论部分?

+0

复制? http://*.com/a/5913539/2063058 http://*.com/questions/2610112/beautifulsoup-and-mechanize-to-get-ajax-call-result – tiktok

+0

我需要看看哪些是URl提取评论?我在页面中搜索了HTML但找不到它。有人可以告诉我的网址? – Umair

+0

http://*.com/a/5995713/2063058 – tiktok

你为什么这么复杂?

就去做,

soup.find("span",{"itemprop":"aggregateRating"}).text.encode('ascii','ignore').replace('\n',' ') 

Out[]: 
Rated 3.4 out of 5by 625 reviewers. 

是不是你需要什么?

+0

在你的情况下,它将'hotel_page_soup.find'而不是'soup.find' –

+0

我会试一试... – Umair

+0

@Umair你试过了吗? –

工作代码

rev = hotel_page_soup.find("span", 
          { "itemprop": "aggregateRating" } 
          ).text.encode('ascii', 
              'ignore' 
              ).replace('\n', ' ') 

for total_rating_score in rev.select("span"): 
    print (total_rating_score.string) 
+0

你的答案甚至不会工作。 'rev'是一个字符串,并且不会与'rev.select'一起使用这很荒谬。你问问题,当有人回答你时,只需稍微修改一些甚至不正确的东西,然后自己发布? –