嘿,伙计们,我做了一个抓取程序,从网站上抓取一些信息,现在我需要把这些信息放到google工作表中,我想知道最好的方法是什么?将其转换为csv文件,然后将其放入工作表中?或者其他任何我愿意接受建议的事情。
发布于 2020-03-04 17:51:02
使用google APIs是一种更好的方法,可以避免资源密集型文件读/写操作。
Pre-req:创建一个服务帐户并准备好密钥json,下面是python的示例代码:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import datetime
SCOPE = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
SAMPLE_SPREADSHEET_ID = 'xxxxxx'
def update_cell(cell, value):
credentials = ServiceAccountCredentials.from_json_keyfile_name('downloaded.json', SCOPE)
gc = gspread.authorize(credentials)
wks = gc.open_by_key(SAMPLE_SPREADSHEET_ID).get_worksheet(1)
wks.update_acell(cell, value)
if __name__ == '__main__':
update_cell('A1', 'test')
发布于 2020-03-04 17:51:49
https://stackoverflow.com/questions/60522818
复制相似问题