やりたいことは毎朝6時に自分のLINEにスクレイピングしてきた情報を通知したい。
pythonのscheduleなどは使わずxサーバーでやることは可能でしょうか。
※かなり初心者なので記述がへんてこりんなのはご了承下さい。
宜しくお願い致します。
import requests from bs4 import BeautifulSoup # 天気情報 z = 0 box1 = [] while True: z += 1 r = requests.get('https://weather.yahoo.co.jp/weather/jp/11/?day=' + str(z) + '') soup = BeautifulSoup(r.content, "html.parser") days = soup.select_one('#navCal li:nth-of-type(' + str(z) + ')') days_wrap = days.getText() temp = soup.select_one('li.pt4310 .temp') temp_wrap = temp.getText() precip = soup.select_one('li.pt4310 .precip') precip_wrap = precip.getText() box1.append(days_wrap + ' ' + '最高/最低気温:' + temp_wrap.replace('\n', '') + '\n' + '降水確率:' + precip_wrap.replace('\n', '')) if z == 3: break total = '\n' + box1[0] + '\n' + box1[1] + '\n' + box1[2] # LINE line_notify_token = '※lineのアクセストークン' line_notify_api = 'https://notify-api.line.me/api/notify' message = total payload = {'message': message} headers = {'Authorization': 'Bearer ' + line_notify_token} # 発行したトークン line_notify = requests.post(line_notify_api, data=payload, headers=headers)
あなたの回答
tips
プレビュー