前提
実現したいこと
あるwebサイトのhtmlを取得
→クラスを指定して要素を取得
→これを定期実行
→要素が変化したら(サイトが更新されたら)trueを返す
というプログラムを作成しています。
定期実行に関してはをgoogleのcloud functionsのpubsubトリガーで行います。
発生している問題・エラーメッセージ
コードはgoogle colaboratoryで実行するとうまくいきました。
しかしcloud functionsでデプロイ後,関数をテストすると下記のエラーが出ます。
Error: function terminated. Recommended action: inspect logs for termination reason. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging Details:500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
該当のソースコード
言語はpythonです。
from bs4 import BeautifulSoup import requests def detect_updates(): url = "webサイトのurl" res = requests.get(url) soup = BeautifulSoup(res.text,'html.parser') #new_elemに取得したclassの要素を入れる new_elem = str(soup.select(".クラス名")) #old_elem.txtに入っているclassの要素をold_elemに入れる try: with open("old_elem.txt") as f: old_elem = f.read() except: old_elem = "" #old_elemとnew_elemを比較 if new_elem == old_elem: return False else: with open("old_elem.txt","w") as f: f.write(new_elem) return True
試したこと
ログを見たところ,これが原因の文章かと思われます。
TypeError: detect_updates() takes 0 positional arguments but 2 were given
コメントアウトなどして原因箇所を探ってみましたが,分からず。
最終的に下記のコードでテストしても同じエラーが出てきました。
def detect_updates(): print("aaa")
補足情報(FW/ツールのバージョンなど)
下記の動画を参考に作成しました。
https://www.youtube.com/watch?v=1-UOksMm0r8

回答1件
あなたの回答
tips
プレビュー