zoukankan      html  css  js  c++  java
  • Python脚本:过滤取指定链接标题是否含有指定文字,并将其输出

    #coding=utf-8
    import requests
    import threading
    import time
    import os

    def check(i,total):
    global eu
    #os.system("title Spider,Current threads: %d,URLs left: %d,URLs
    exists:%d" %(threading.active_count(),total,eu))
    try:
    r = requests.get(i+'/',timeout=10) #链接后缀,如果没有可以
    不加,timeout是超时时间
    status=r.content.count('指定文字')
    except:
    print i,'超时'
    status = 0
    if status !=0: #通过标题判断
    r = 0
    print i,'成功!!!!!'
    eu+=1
    f = open("成功的文件保存.txt", 'a')
    f.write(i+' ')
    f.close()

    def main():
    global eu
    eu = 0
    total=len(open('等待过滤的链接.txt','rU').readlines())
    print 'Total URLs:%d' %total
    for i in open("等待过滤的链接.txt").readlines():
    i=i.strip(' ')
    t=threading.Thread(target=check, args=(i,total))
    t.setDaemon(True)
    total-=1
    while True:
    if(threading.active_count() == 1 and total == 0 ):
    print 'All Done at %s' %time.strftime
    ("%Y-%m-%d[%H.%M.%S]")
    break
    elif (threading.active_count() < 200):
    if (total == 0):
    time.sleep(10) #10秒之后回到上一个
    if判断线程是否全部结束
    else:
    os.system("title Spider,Current
    threads: %d,URLs left: %d,URLs exists:%d" %(threading.active_count
    (),total,eu))
    t.start() #加载该线程
    break


    if __name__ == '__main__':
    main()

  • 相关阅读:
    安装pipenv
    ModuleNotFoundError: No module named 'pip._internal' , pip 无法下载软件 解决办法
    1.3用户列表 and 新闻列表
    1.2用户统计页面实现
    1.5发布新闻
    七牛云平台(存储图片)
    1.2头像设置功能
    1.4用户收藏展示
    1.3密码修改
    1.2首页刷新以及点击排行
  • 原文地址:https://www.cnblogs.com/cbreeze/p/5845398.html
Copyright © 2011-2022 走看看