python爬取网站分析

获取到网站信息并分析
import requests,re
from requests.auth import HTTPBasicAuth
from lxml import etree
EnterInput = input("""pealse select
---------------------
|1.goodworkers       |
---------------------
|2.goodworkers4      |
---------------------
|3.wrongworkers      |
---------------------
|4.offlineworkers    |
---------------------
|5.delOfflineWorker  |
---------------------
|6.delOfflineWorker  |
---------------------
|7.unknowworkers     |
---------------------
请输入:""")
#获取页面li数据列表
def GetHtmlIp(COUNT):
    count = int(COUNT)
    #网站有BasicAuth验证
    auth = HTTPBasicAuth("yzq".encode('utf-8'), "8888888")
    resopnse = requests.get("网址", auth=auth)
    #获取到的是一个数据
    html = etree.HTML(resopnse.text)
    #{}接受一个数据可选择获取那个对象的数据
    name = html.xpath('//div[@class="box"]/dl[{}]/dd/li'.format(int(count)))
    #获取到数据是一个列表
    for i in name:
    	#对第2个函数进行什么样的数据分析
        if count == 2:
            print(str(i.text).split(",")[0])
        if count == 4:
            if str(i.text).split(" ")[0].split("-")[0]:
                ErrorOut = str(i.text).split(" ")
                if 'no' in ErrorOut and 'host':
                    print(ErrorOut[0])
        elif str(i.text).split(" ")[0].split("-")[0]:
            print(str(i.text).split(" ")[0].split("-")[1])
if __name__ == '__main__':
    GetHtmlIp(EnterInput)
获取到网站信息并筛选自己想要的信息
import requests,json
import time
#//第二版
messlist = {}
net = {'AccountInfo': {
    '111': '111',
    '1112': '1113',
}}
ples = {
    '111': '111',
    '1121': '1112',
}
def AccountManagement():
    for i,j in net['AccountInfo'].items():
        t023200 = 'https://filfox.info/api/v0/address/{}/messages?pageSize=1&page=0'.format(i)
        res = requests.get(t023200)
        t023200_balance = 'https://filfox.info/api/v0/address/{}/balance-stats?duration=24h&samples=1'.format(j)
        res1 = requests.get(t023200_balance)
        messlist[i] = res.text
        messlist[j] = res1.text
    return messlist
def info(jy):
    url = 'https://oapi.dingtalk.com/robot/send?access_token=59eeb069d68957c6c09f1d169fa908b77470481751d3634fa25ecf06e12831bb'
    headers = {
        'Content-Type': 'application/json;charset=utf-8'
    }
    formdata = {
        "msgtype": "text",
        "text": {"content": str(jy)}
    }
    requests.post(url=url, data=json.dumps(formdata), headers=headers)
def get_messages(count):
    for accountkey,accountvalue in count.items():
        if len(accountkey) < 10:
            accountvalue=eval(accountvalue)['messages']
            for i in accountvalue:
                timestamp= i['timestamp']
                account_number=i['to']
                if timestamp:
                    now = time.time() - timestamp
                    Datetime = time.gmtime(now)
                    if int(Datetime.tm_min) >= 4:
                        data = "账号:{}相差{}时{}分无消息.".format(account_number,Datetime.tm_hour,Datetime.tm_min)
                        info(data)
                    else:
                        pass
def GetBalance(Bla):
    for accountkey, accountvalue in Bla.items():
        if len(accountkey) > 10:
            Bla = eval(accountvalue)
            Balance = round(int(Bla[0]['balance']) / 1000000000000000000)
            if Balance < 100:
                if accountkey == '111':
                    print(accountkey)
                    data = "XXX:{}\r不足100:\r还剩余{}.".format(accountkey,Balance)
                    info(data)
                if accountkey == '1112':
                    print(accountkey)
                    data = "XXX:{}\r不足100:\r还剩余{}.".format(accountkey,Balance)
                    info(data)
if __name__ == '__main__':
    get_messages(AccountManagement())
    GetBalance(AccountManagement())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值