VPS/独立服务器上货监控脚本

有些VPS或者独立服务器的性价比很高,基本上供不应求,这个时候,仅仅可以靠人力去刷新页面是很难买到的。而一个定时运行的脚本则可以替我们实现这个功能。于是写了一个python3的监控程序,配合server酱可以实现实时微信推送。
程序放在Github上,点击这里查看,程序名称为oos.py,取Out of Stock之意。

# !/usr/bin/env python3
# -*- coding: UTF-8 -*-
from urllib import request
import requests
from datetime import datetime
timeout = 10
time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
key = 'SCKEY'
title = "上货监测"
url = ""
head = {
'Connection': 'Keep-Alive',
'Accept': 'text/html, application/xhtml+xml, */*',
'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko'
}
try:
req = request.Request(url, headers=head)
response = request.urlopen(req, timeout=timeout)
html = response.read()
html = html.decode("utf-8").lower()
str="out of stock"
if str in html:
print("缺货" + "n" + time)
else:
print("不缺货" + "n" + time)
content = "上货啦~" + "n" + time
payload = {
'text': title,
'desp':content
}
fturl = 'https://sc.ftqq.com/{}.send'.format(key)
requests.post(fturl, params=payload, timeout=timeout)
except Exception:
print("Error" + "n" + time)

其中的url为VPS/独立服务器的购买页面;SCKEY为server酱的密钥,可以点击这里免费申请一个;str="out of stock"这一行为页面关键字监控,可以自行更改,一般都是out of stock;配合crontab可以实现10秒级别的上货查询!

全部为采集文章,文中的 联系方式 均不是 本人 的!

发表评论