来自TA的Scrap评论用于树状图

时间:2018-03-12 02:41:39

标签: python-3.x

Python 3

我正试图从tripadvisor那里获取至少20家不同餐厅的评论,这些餐厅提供至少4种不同的美食,即意大利,希腊,美国和中国。最后,我想创建一个树形图,以查看结果中的潜在聚类。到目前为止,我有以下内容,但我不确定是否可以直接从结果页面获取评论,或者我是否必须进入每个餐厅pg:

from urllib.request import urlopen
from bs4 import BeautifulSoup
url = "https://www.tripadvisor.com/Restaurants-g60763New_York_City_New_York.html"
response = urlopen(url)
soup = BeautifulSoup(response, "html.parser")

restaurants = []
for div in soup.findAll('div', {'class': 'ui_column is-9 shortSellDetails'}):
    for div in div.findAll('div', {'class': 'title'}):
        for a in div.findAll('a'):
            restaurants.append(a.text)
print(len(restaurants))

0 个答案:

没有答案