Python 我的第一个程序
发布时间:2020-12-17 17:14:18 所属栏目:Python 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 import socketclass HttpClient(object): def __init__ (this,args): this.host = args["host"] this.port = args["port"] this.userAgent = args["us
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 import socket class HttpClient(object): def __init__ (this,args): this.host = args["host"] this.port = args["port"] this.userAgent = args["userAgent"] this.buffer = "" def build (this): this.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) this.sock.connect((this.host,this.port)) this.sock.send("GET / HTTP/1.1rn") this.sock.send("Host: " + this.host + "rn") this.sock.send("Connection: closern") this.sock.send("User-Agent: " + this.userAgent + "rn") this.sock.send("Content-type: application/x-www-form-urlencodedrn") this.sock.send("rnrn") def get(this): this.build(); while True: buf = this.sock.recv(8192) if(buf): this.buffer += buf else: break return this.buffer def __del__(this): this.sock.close() if __name__ == '__main__' : args = {"host" : "www.haowei.me","port" : 80,"userAgent" : "MSIE"} print HttpClient(args).get() 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |