前提・実現したいこと
pythonで外務省のサイトをスクレイピングして
SDGs推進企業の一覧をグーグルスプレッドシートに
「企業名」「企業サイトURL」を取得したいです。
APIの上限に引っかからずにできる方法ってありますか?
解決策としてはdataframeを使ってやれば良いのかなーと思っています。
発生している問題・エラーメッセージ
1件ずつ企業名とURLをセルにwks.update_acellで実行しており
APIの上限に引っかかります。
"error": { "code": 429, "message": "Quota exceeded for quota group 'WriteGroup' and limit 'Write requests per user per 100 seconds' of service 'sheets.googleapis.com' for consumer 'project_number:********.", "status": "RESOURCE_EXHAUSTED", "details": [ { "@type": "type.googleapis.com/google.rpc.Help", "links": [ { "description": "Google developer console API key", "url": "https://console.developers.google.com/******" } ] } ] } }
該当のソースコード
Python
1import requests 2from bs4 import BeautifulSoup 3import gspread 4from oauth2client.service_account import ServiceAccountCredentials 5 6scope = ['**********'] 7credentials = ServiceAccountCredentials.from_json_keyfile_name('********', scope) 8gs = gspread.authorize(credentials) 9wks = gs.open('******').sheet1 10 11a = 2 12r = requests.get(r"https://www.mofa.go.jp/mofaj/gaiko/oda/sdgs/case/org1.html") 13soup = BeautifulSoup(r.content,"html.parser") 14tags = soup.select(".exlink") 15for tag in tags: 16 name = tag.string 17 href = tag.attrs['href'] 18 wks.update_acell('A'+str(a),name) 19 wks.update_acell('B'+str(a),href)
試したこと
上限をあげると無料トライアルからグレードを上げないといけないので、
それは避けたいです。
補足情報(FW/ツールのバージョンなど)
Python3.7
エディタ:Visual Studio Code
回答2件
あなたの回答
tips
プレビュー