梦达流量卡 自动复机

由于流量稀缺,上两个月在联通买了流量卡,开始用得时候还行,不过用着用着就废物了。

  1. 流量卡的网速限制在300k以内,问了客户,说他们系统信息正常,可能是基塔问题,说白了,就是白问了,没办法解决。
  2. 流量卡每隔一段时间就需要‘自助复机’

我对流量无非是微信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,放弃使用该流量卡作为手机流量卡。
不过流量总体性价比还是比较高,比较适合做小流量长服务的应用场景。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值