Skip to content

Instantly share code, notes, and snippets.

@abc1763613206
Last active December 1, 2019 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abc1763613206/dc8a9b1cb76e5d80b39327232d090e0a to your computer and use it in GitHub Desktop.
Save abc1763613206/dc8a9b1cb76e5d80b39327232d090e0a to your computer and use it in GitHub Desktop.
compare
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