【问题标题】:Import data from Tripadvisor to Google Spreadsheets or Excel将数据从 Tripadvisor 导入 Google 电子表格或 Excel
【发布时间】:2020-09-16 16:19:36
【问题描述】:

是否可以获得这些数据的列表: https://www.tripadvisor.com/Restaurants-g188590-Amsterdam_North_Holland_Province.html

在 Google 电子表格中?

那么,阿姆斯特丹所有餐厅的清单。如果可能,请提供地址详细信息等。

请告诉我!

非常感谢!

【问题讨论】:

    标签: excel web-scraping import tripadvisor


    【解决方案1】:

    我们可以通过两种方式使用python实现结果

    1. 使用网络抓取框架从您的链接中提取数据,并使用 pyexcel 框架将数据写入您的 excel 文件。

    下面的链接详细解释了如何使用 python 进行网页抓取 https://realpython.com/python-web-scraping-practical-introduction/

    1. 使用 selenium 和 pyexcel

    如果数据需要存储在 Google 表格中,请使用 gspread 框架

    【讨论】:

      【解决方案2】:

      这是一个示例,但使用的是 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")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-23
        • 2016-10-27
        • 2014-07-22
        • 2014-07-31
        • 2014-02-24
        相关资源
        最近更新 更多