いくつかのオンラインツイート(Bucky)の助けを借りて、私はいくつかのテキストがウェブページ上にあるかどうかをチェックする単純なウェブスクレーパーを書くことができました。しかし私がしたいことは、毎時間コードを実行させることです。私はコードをホストする必要もあると思います私はいくつかの調査をしましたが、毎時間それを実行する適切な方法を見つけることができないようです。私の機能を1時間ごとに実行するには?
import requests
from bs4 import BeautifulSoup
def odeon_spider(max_pages):
page = 1
while page <= max_pages:
url = "http://www.odeon.co.uk/films/rogue_one_a_star_wars_story/16038/" + str(page) #stores url in variable
source_code = requests.get(url) #gets url and sets it as source_code variable
plain_text = source_code.text #stores plain text in plain_text variable
soup = BeautifulSoup(plain_text, "lxml") #create beautifulsoup object
div_content = soup.findAll("div", {"class": "textComponent"}) #finds all divs with specific class
for x in div_content:
find_para = str(x.find('p').text) #finds all paragraphs and stores them in variable
text_to_search = "Register to be notified" #set text to search to variable
if text_to_search in find_para: #checks if text is in find_para
print("No tickets")
else:
print("Tickets")
page += 1
odeon_spider(1)
ありがとう:ここに は、私がこれまで持っているコードです!
Linuxマシンの場合は 'crontab'を使用してください –
Linuxの場合はcronjobを使います。windowsの場合はtaskschedulerを使用できます –