【问题标题】:Exporting scraped content to google sheets将抓取的内容导出到谷歌表格
【发布时间】:2019-10-13 09:22:27
【问题描述】:

我愿意在网站上抓取一些信息。这将是 3 到 4 列。困难的部分是,我想将所有数据导出到谷歌表格中,并让爬虫在特定时间间隔后运行。为此,我将使用scrapy。关于如何做到这一点的任何建议(通过制作自定义管道或任何其他方式,因为我在编写自定义管道方面没有太多经验)

【问题讨论】:

    标签: python python-3.x web-scraping scrapy


    【解决方案1】:

    您可以使用 Google API 和 python pygsheets 模块。 更多详情请参考此链接Click Here

    请查看示例代码,这可能会对您有所帮助。

    import pygsheets
    import pandas as pd
    #authorization
    gc = pygsheets.authorize(service_file='/Users/desktop/creds.json')
    
    # Create empty dataframe
    df = pd.DataFrame()
    
    # Create a column
    df['name'] = ['John', 'Steve', 'Sarah']
    
    #open the google spreadsheet (where 'PY to Gsheet Test' is the name of my sheet)
    sh = gc.open('PY to Gsheet Test')
    
    #select the first sheet 
    wks = sh[0]
    
    #update the first sheet with df, starting at cell B2. 
    wks.set_dataframe(df,(1,1))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多