zoukankan      html  css  js  c++  java
  • python代理检测

    import socket,threading,os,sys,queue,re
    socket.setdefaulttimeout(5)
    path=sys.path[0]
    if os.path.isfile(path):
        path=os.path.split(path)[0]

            

    domain='www.baidu.com'
    que=queue.Queue()
    tno=20
    a=open(path+r'proxy.txt').read().strip().split()
    for i in a:
        que.put(i.split(':'))
        

    data='''GET http://www.baidu.com/ HTTP/1.1
    Host: www.baidu.com
    User-Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.46 Safari/535.11
    Accept: */*
    Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3

    '''


    def geturl():
        while True:
            if que.empty():
                return False
            proxy,port=que.get(timeout=1)
            try:
                s=socket.socket()
                s.connect((proxy,int(port)))
                s.send(data.encode())
                da=s.recv(1024).decode('utf8','ignore')
                if '200 OK' in da:
                    open(path+r'proxyok.txt','at').write(proxy+':'+port+' ')
                    print(proxy+':'+port,'可用')
            except Exception as err:
                print(proxy,port,err)
                print(proxy,port,err,file=open(path+r'err.txt','at'))
                pass
            finally:
                s.close()

    for i in range(tno):
        threading.Thread(target=geturl).start()
  • 相关阅读:
    2019年3月博客汇总
    赞美郭老师
    多项式初步
    Linux 下安装配置 JDK
    Python搜索目录下指定的文件,并返回绝对路径(包括子目录)
    Python所有的错误都是从BaseException类派生的,常见的错误类型和继承关系
    Python地址簿
    PHP正确的使用复数
    seq
    date
  • 原文地址:https://www.cnblogs.com/jackyshan/p/3545524.html
Copyright © 2011-2022 走看看