本帖最后由 不羁的阳光 于 2021-7-23 08:40 编辑
[Python] 纯文本查看 复制代码 # -*- coding = utf-8 -*-
# [url=home.php?mod=space&uid=238618]@Time[/url] : 2021/7/22 18:55
# Author : Wall.E
# [url=home.php?mod=space&uid=267492]@file[/url] : RIKIPush.py
# [url=home.php?mod=space&uid=371834]@SOFTWARE[/url] : PyCharm
import time
import requests
from lxml import etree
import redis
import random
import winsound
GjKey=['红包','攻略','优惠','首发','大毛','速度','作业','大水','翼支付','有水','白嫖','0元','手慢无']
def log(*args, **kwargs):
format = '%Y/%m/%d %H:%M:%S'
value = time.localtime(int(time.time()))
dt = time.strftime(format, value)
print(dt, *args, **kwargs)
def getmidstring(html, start_str, end):
start = html.find(start_str)
if start >= 0:
start += len(start_str)
end = html.find(end, start)
if end >= 0:
return html[start:end].strip()
def getrikimsg():
while True:
url1 = "https://www.hxm5.com/xianbao/2/"
headers = {
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
}
res1 = requests.get(url=url1, headers=headers).text
tree = etree.HTML(res1)
tb_list = tree.xpath('//div[1]/ul/li')
for tb in tb_list[6:]:
tittle = tb.xpath('./div/h2/a/text()')[0]
#print(tittle)
tittle_url = tb.xpath('./div/h2/a/@href')[0]
# print(tittle_url)
ex=r.sadd('tids',tittle_url)
if ex==1:
url2 = 'https://www.hxm5.com' + tittle_url
res2 = requests.get(url=url2, headers=headers).text
tree2 = etree.HTML(res2)
nr = tree2.xpath('//*[@id="topic-desc"]/p/text()')
log(tittle+'\n', url2+'\n', nr)
for GJ in GjKey:
if GJ in tittle:
winsound.Beep(440, 1500)
break
time.sleep(random.randint(10, 30))
else:
log('网站无更新')
time.sleep(random.randint(30, 90))
break
if __name__ == '__main__':
poor = redis.ConnectionPool(host='localhost', port=6379, decode_responses=True)
r = redis.Redis(connection_pool=poor)
for key in r.keys():
r.delete(key) # 清除所有数据
getrikimsg()
注意:1,安装PY环境,2,安装REDIS数据库,3,安装那几个第三方库,然后就OK了
|