Python 我的第一个程序,Python第一个程序,import socke
文章由Byrx.net分享于2019-03-23 05:03:23
Python 我的第一个程序,Python第一个程序,import socke
import socketclass 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.1\r\n") this.sock.send("Host: " + this.host + "\r\n") this.sock.send("Connection: close\r\n") this.sock.send("User-Agent: " + this.userAgent + "\r\n") this.sock.send("Content-type: application/x-www-form-urlencoded\r\n") this.sock.send("\r\n\r\n") 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()
相关内容
- 20行构建哈夫曼树,20行哈夫曼,import rando
- Python操作Word批量生成文章,pythonword文章,需要做一些会
- 汉诺塔实现,,# -*- coding
- python实现将excel数据添加到mongodb,pythonmongodb,在做文本
- python删除特定文件,python删除,#!/usr/bin/p
- pygame wormy 贪吃蛇,pygamewormy,import pygam
- python黑客写阶乘,python黑客阶乘,import sys@t
- apriori算法,,"""Descripti
- 用Python dpkt 来解析 pcap ,,,dpktpcap,import pcap,
- 计算文件大小,,#-*- coding:
评论关闭