
Python 使用 requests 套件將資料寫入 Google 試算表
今天要來介紹,如何使用 Python 的 requests 套件,將資料寫入 Google 試算表。
1. 首先先照著下篇教學,把 Google 表單和試算表建立起來。
使用 App Inventor 將文字欄位資料寫入 Google 試算表 – JB 程式筆記 (jbprogramnotes.com)



2. 開啟 Google Colab 並新增一個筆記本「Python2GSheets」
或用妳慣用的編輯器也行~~

輸入以下程式碼:
安裝套件
pip install -U requests
匯入套件
import requests
設定變數
url = "https://docs.google.com/forms/d/1SBfuw1ILRgf8GUZvgJ-6yuukgCr9Dk6MPeby-Ea6qT8/formResponse?"
id = "JamesB"
content = "今天開始變冷了!"
更新網址變數
url += "entry.22988834=" + id + "&entry.1255317433=" + content
呼叫 requests 套件的方法,執行 GET 請求,並查看回應碼是否為 200。
r = requests.get(url)
print(r.status_code)

好了之後依序執行,全部成功後,資料就會顯示在 Google 試算表囉!

Google Colab 連結
https://colab.research.google.com/drive/1iv1uSb7bYXMSZ9WNG50EKv8657zaMpxr?usp=sharing
Google 試算表連結
https://docs.google.com/spreadsheets/d/1cQ7x2LYHKfaWBL3WrrtvyVArIsyHPXbF6i8zlgGMYM0/edit?usp=sharing
範例程式執行影片
如果覺得文章內容還不錯的話,麻煩請幫我點個讚!感謝
可以多點幾次喔~~
第一次點讚需使用 Google 或 Facebook 帳號註冊

![[教學文章 分享/改編] 突破 App Inventor 30 MB 限制 Part 3](https://i0.wp.com/i.imgur.com/23qf8Jx.png?resize=75%2C75&ssl=1)