Last active
December 1, 2019 03:07
-
-
Save abc1763613206/dc8a9b1cb76e5d80b39327232d090e0a to your computer and use it in GitHub Desktop.
compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import traceback | |
from time import sleep | |
from bs4 import BeautifulSoup as bs | |
import requests | |
url = 'https://www.januslaboratorium.com/sitemap.xml' | |
def sendMessage(text): | |
pass | |
def getHtml(): | |
try: | |
ret = requests.get(url) | |
ret.raise_for_status() | |
return ret.text | |
except Exception as e: | |
traceback.print_exc() | |
sendMessage('抱歉:请求出现错误:'+str(repr(e))) | |
#file = f.read() | |
def processData(): | |
origin = getHtml() | |
soup = bs(origin, "html.parser") | |
links = soup.find_all('loc') | |
link = links[0].text | |
if not os.path.exists("last.txt"): | |
f = open('last.txt','w+') | |
f.write(link) | |
f.close() | |
sendMessage('链接初始化:'+link) | |
pass | |
f = open('last.txt','r') | |
lst = f.read() | |
if str(link) == str(lst): | |
pass | |
else: | |
f = open('last.txt','w+') | |
f.write(link) | |
f.close() | |
sendMessage('链接已更新:'+link) | |
while 1: | |
processData() | |
sleep(120) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment