简体   繁体   English

从 python 脚本更新谷歌表

[英]Update google sheet from python script

I'm trying to have a python script update a google sheets.我正在尝试让 python 脚本更新谷歌表格。 The script scrapes a dynamically loaded webpage and retrieves some values.该脚本抓取动态加载的网页并检索一些值。

Because the site loads dynamically, I can't use google scripts.因为网站是动态加载的,所以我不能使用谷歌脚本。 But if I wan't the python script to access the google sheet, I need a google service account.但如果我不想使用 python 脚本来访问谷歌表格,我需要一个谷歌服务帐户。 This requires a credit card, but I don't have access to a non-prepaid one.这需要一张信用卡,但我无法使用非预付卡。

I could also host the python API on gae, but this also requires a credit card.我还可以在 gae 上托管 python API,但这也需要信用卡。

Any ideas for how I could work around this?关于如何解决这个问题的任何想法?

I believe your goal as follows.我相信你的目标如下。

  • You want to put the values to Google Spreadsheet using python.您想使用 python 将值放入 Google 电子表格。

In order to achieve your goal, how about the following patterns?为了实现您的目标,以下模式如何?

1. Access to Google Spreadsheet using Sheets API with OAuth2. 1. 使用带有 OAuth2 的 Sheets API 访问 Google 电子表格。

When Sheets API is used, the values can be put to the Google Spreadsheet.当使用表格 API 时,可以将值放入 Google 电子表格。

In this case, you can see the sample script at Quickstart .在这种情况下,您可以在Quickstart中查看示例脚本。 And, I think that in your situation, the use of Google Sheets API is free of charge.而且,我认为在您的情况下,使用 Google 表格 API 是免费的。 If you want to increase the quota of Sheets API, please check it at https://developers.google.com/sheets/api/limits .如果您想增加 Sheets API 的配额,请查看https://developers.google.com/sheets/api/limits

2. Access to Google Spreadsheet using Sheets API with Service account. 2. 使用带有服务帐户的表格 API 访问 Google 电子表格。

When Sheets API is used, the values can be put to the Google Spreadsheet.当使用表格 API 时,可以将值放入 Google 电子表格。

In this case, you can see the sample script from these threads .在这种情况下,您可以从这些线程中看到示例脚本。 And also, I think that in your situation, the use of Google Sheets API is free of charge.而且,我认为在您的情况下,使用 Google 表格 API 是免费的。

3. Access to Google Spreadsheet using Web Apps created by Google Apps Script. 3. 使用由 Google Apps 脚本创建的 Web 应用程序访问 Google 电子表格。

When Google Apps Script is used, the values can be put to the Google Spreadsheet.使用 Google Apps 脚本时,可以将值放入 Google 电子表格。 And, in this method, Google Apps Script is used as the wrapper.并且,在此方法中,Google Apps 脚本用作包装器。

At first, create Web Apps using Google Apps Script, and your python script accesses to the Web Apps by sending the values with requests module.首先,使用 Google Apps 脚本创建 Web 应用程序,然后您的 python 脚本通过使用requests模块发送值来访问 Web 应用程序。 By this, at the Web Apps side, the retrieved values are put to Google Spreadsheet using Google Apps Script.这样,在 Web 应用程序端,检索到的值使用 Google Apps 脚本放入 Google 电子表格。 The Web Apps is used as the wrapper API for using Google Spreadsheet. Web 应用程序用作包装器 API 以使用 Google 电子表格。 And also, in this case, you can also access to the Web Apps with and without using the access token.此外,在这种情况下,您还可以使用和不使用访问令牌访问 Web 应用程序。 In this method, I think that your python script is simple modification.在这个方法中,我认为你的 python 脚本是简单的修改。

In this case, you can see the detail information about Web Apps at Web Apps and Taking advantage of Web Apps with Google Apps Script .在这种情况下,您可以在Web 应用程序利用 Web 应用程序与 Google Apps 脚本中查看有关 Web 应用程序的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM