python不会抓取文本,但给了我一个空白的空格



我正试图从Trip Advisor网站上获取一些客户评论。对于一些评论,我可以毫无问题地抓取,但对于其他评论,我无法正确抓取。它只是给了我一个空白的空间。有人能帮忙吗?下面是我的简化代码。

from urllib.request import urlopen
from bs4 import BeautifulSoup
import re 
b_link="https://www.tripadvisor.com/ShowUserReviews-g60607-d1468361-r460991443-Ohana_House_Volcano_s_Popular_Rainforest_Retreat-Volcano_Island_of_Hawaii_Hawaii.html"
links_open_b=urlopen(b_link)
soup_b=BeautifulSoup(links_open_b,"html.parser")
first_text_b=soup_b.find_all("div", class_="entry vrReviewText")
actual_text_b=first_text_b[0].text
actual_text_b=re.sub('s+',' ',actual_text_b)
print (actual_text_b)

我能得到的:

Just an empty white space.

我想要得到的:Volcano的Ohana房子非常适合我们全家和我们在大岛的5天住宿。。。。我们在访问的各个方面都度过了美好的时光,强烈建议任何想探索大岛东侧的人参观这所房子。

评审实际上是通过加载的

https://www.tripadvisor.com/UserReviewController?a=fullTrans&r=460991443

要获得审查,您可以使用requests模块:

import requests
URL = "https://www.tripadvisor.com/UserReviewController?a=fullTrans&r=460991443"
response = requests.get(URL).json()
print(response[0]["body"])

输出:

The Ohana house at Volcano ... side of the Big Island.

最新更新