简易版 值得买推送,仅支持新消息服务
本帖最后由 叫我小王叔叔 于 2021-5-10 10:35 编辑自学python,一直观察并抄袭大佬们代码,整合了一下,有了下面这个东西,参考了@白白io的api和@culprit的云函数。
import requests,random,json
from bs4 import BeautifulSoup
def UserAgent(): #随机获取请求头
user_agent_list = ['Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1464.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.3319.102 Safari/537.36',
'Mozilla/5.0 (X11; CrOS i686 3912.101.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36',
'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:17.0) Gecko/20100101 Firefox/17.0.6',
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1468.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2224.3 Safari/537.36',
'Mozilla/5.0 (X11; CrOS i686 3912.101.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36']
UserAgent=random.choice(user_agent_list)
return UserAgent
def wxpush(text,article_url):
headers = {"User-Agent": UserAgent(),"Content-Type":"application/json"}
url = "http://wxpusher.zjiecode.com/api/send/message"
data = {
"appToken": "你自己的",
"content": text,
#"summary":text,
"contentType":2,
"uids": ["你自己的"],
"url": article_url
}
r = requests.post(url, headers=headers, data=json.dumps(data))
def check(keys):
for key in keys:
url = "https://api.smzdm.com/v1/list?f=wxapp&wxapp=zdmapp&order=time&keyword=" + key + "&offset=0&limit=3&category_name="
s = requests.session()
r = s.get(url, headers={"User-Agent": UserAgent()})
#r.encoding='gb2312'
#print(r.text)
data=r.json()
goods=data["data"]["rows"]
#print(goods)
for good in goods:
article_title = good["article_title"]
article_price = good["article_price"]
#article_format_date = good["article_format_date"]
#article_pic = good["article_pic"]
#article_mall = good["article_mall"]
article_url = good["article_url"]
text=article_title+article_price
wxpush(text,article_url)
def checkuids(uids):
goods_list = []
try:
for uid in uids:
url = "https://zhiyou.smzdm.com/member/" + uid + "/baoliao/"
response = requests.get(url, headers={"User-Agent": UserAgent()}).content
soup = BeautifulSoup(response, 'html.parser', from_encoding='utf-8')
html = soup.find_all(name='div', attrs={'class': 'pandect-content-title'})
for i in html:
goods_list.append(i.a.get_text().strip() + ' ——> ' + i.a['href'].strip())
wxpush(i.a.get_text().strip(), i.a['href'].strip())
if goods_list:
break;
except Exception as e:
print(e)
if __name__ == "__main__":
goods=['除湿机']#商品关键字,可以自己添加
check(goods)
uids=['9687682701', '5160345630']#什么值得买爆料人ID,可以自己添加
checkuids(uids)
应该再加一个本地的文件,保存上次更新的东西,如果有更新就推送,没有就歇着。
初学,没什么方法,能实现需求就好。 licaiyoudao43 发表于 2021-5-19 07:51
目前在你的基础上添加了INI配置,可以和本地保存的进行比较,当出现新爆料时才发送。但是有BUG,当商品带 ...
我没这么干,我直接放了列表的,抓回来之后先跟列表比较一下,在里面就什么都不干,不在里面再更新,完事儿更新列表,挺稳定的,centos nohub运行后,后台稳定运行了5天了。唯一的缺点就是云函数不能用了,话说你这ini云函数好用么? 很实用的东西,其实应该可以拿来生成推送吧 感谢分享经验,谢谢。 膜拜膜拜 前排学习 感觉论坛里面好多大佬啊~~~ 这是什么东西?干什么用的? 这个WxPusher,是借用的他的公众号,能否换成自己的公众号? 经验分享!学习了 很强,楼主加油