由于流量稀缺,上两个月在联通买了流量卡,开始用得时候还行,不过用着用着就废物了。
- 流量卡的网速限制在300k以内,问了客户,说他们系统信息正常,可能是基塔问题,说白了,就是白问了,没办法解决。
- 流量卡每隔一段时间就需要‘自助复机’
我对流量无非是微信qq接收消息,所以第一个问题,我可以忽略,但是第二个问题,我就不能忍了。
于是我想到将 ‘自助复机’ 变成(编程) ‘自动复机’。
好了,下面就是我的代码,以防大家重复造轮子,不过如果拿我的代码做违法的事情,后果自己承担:
from urllib import request
from http import cookiejar
from bs4 import BeautifulSoup as bs
from urllib import parse
import time
web_quary = {}
web_quary['fname'] = '8986061915004666705'
fail_sleep_time = 1 # 建议大于 1s, 后果自负
success_sleep_time = 300 # 建议大于 30s, 后果自负
if __name__ == '__main__':
while (True):
try:
cookie = cookiejar.CookieJar()
handler = request.HTTPCookieProcessor(cookie)
opener = request.build_opener(handler)
url = 'http://midea.heliwebs.com/active'
response = opener.open(url)
t = response.read()
# print(t)
with open('a.html', 'wb') as fw:
fw.write(t)
e = bs(t, features="lxml").find('input')
if e['name'] == '_token':
web_quary['_token'] = e['value']
else:
time.sleep(fail_sleep_time)
continue
web_query_data = parse.urlencode(web_quary).encode('utf-8')
response = opener.open(url, data=web_query_data)
if (response.status == 200):
print(str(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime())) + ': success [sleep 300s]')
else:
print(str(time.strftime("%Y-%m-%d %H:%M:%S",
time.localtime())) + ': faild')
time.sleep(fail_sleep_time)
continue
except Exception as e:
print(e)
time.sleep(fail_sleep_time)
continue
time.sleep(success_sleep_time)
2020年06月26日
由于流量被限流,正常只有200-300kb,放弃使用该流量卡作为手机流量卡。
不过流量总体性价比还是比较高,比较适合做小流量长服务的应用场景。