【发布时间】:2020-09-16 16:19:36
【问题描述】:
是否可以获得这些数据的列表: https://www.tripadvisor.com/Restaurants-g188590-Amsterdam_North_Holland_Province.html
在 Google 电子表格中?
那么,阿姆斯特丹所有餐厅的清单。如果可能,请提供地址详细信息等。
请告诉我!
非常感谢!
【问题讨论】:
标签: excel web-scraping import tripadvisor
是否可以获得这些数据的列表: https://www.tripadvisor.com/Restaurants-g188590-Amsterdam_North_Holland_Province.html
在 Google 电子表格中?
那么,阿姆斯特丹所有餐厅的清单。如果可能,请提供地址详细信息等。
请告诉我!
非常感谢!
【问题讨论】:
标签: excel web-scraping import tripadvisor
我们可以通过两种方式使用python实现结果
下面的链接详细解释了如何使用 python 进行网页抓取 https://realpython.com/python-web-scraping-practical-introduction/
如果数据需要存储在 Google 表格中,请使用 gspread 框架
【讨论】:
这是一个示例,但使用的是 excel 而不是 Google 电子表格。它只抓取地名,但您可以轻松抓取其他信息并保存。
from bs4 import BeautifulSoup
import urllib.request
import bs4 as bs
import xlwt
book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("Sheet 1")
sheet1.write(0, 0, "Names")
url_1 = 'https://www.tripadvisor.com/Restaurants-g188590-Amsterdam_North_Holland_Province.html'
sauce_1 = urllib.request.urlopen(url_1).read()
soup_1 = bs.BeautifulSoup(sauce_1, 'lxml')
x = 1
for names in soup_1.find_all('div',class_='wQjYiB7z'):
sheet1.write(x,0, names.text)
x = x+1
book.save("trial.xls")
【讨论】: