首页 > 解决方案 > 将抓取的内容导出到谷歌表格

问题描述

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

标签: pythonpython-3.xweb-scrapingscrapy

解决方案


您可以使用Google API和 python pygsheets模块。有关详细信息,请参阅此链接单击此处

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

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))

推荐阅读