批量判断流量大于300的小脚本

批量判断流量大于300的小脚本

#!/usr/bin/env pytho 
#encoding:utf-8
#by i3ekr

import requests
from lxml import etree

can = []
quchongfu = []
aizhan = "https://www.aizhan.com/cha/"
with open('./url.txt') as f:
    with open("./ok.txt",'a') as ok:
        r_url = f.readlines()
        for i in r_url:
            url = i.strip("
")
            if "https://" in url:
                url = url.replace("https://","")
            if "http://" in url:
                url = url.replace("http://","")
            spider_url = aizhan + url
            res_html = requests.get(spider_url).text
            selector = etree.HTML(res_html)
            content = selector.xpath('//*[@id="baidurank_ip"]/text()')
            print u"网站:%s 流量:%s"%(url,content)
            #输出日IP大于300的网站
            content = "".join(content)#转换为字符串
            LiuLiang = content.split('~')[0]
            if "," in LiuLiang:
                LiuLiang = LiuLiang.replace(",","")
            if LiuLiang >= 100:
                can.append(url)
                ok.write(url+"
")

for i in can:
    print "[+] %s"%(i)
原文地址:https://www.cnblogs.com/nul1/p/8823755.html