Python 3.x - 一个简单的客户端Get请求程序
2016-02-14 11:38
651 查看
import socket target_host = "www.baidu.com" target_port = 80 # create a socket object client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # connect the client client.connect((target_host,target_port)) # send some data data = "GET / HTTP/1.1\r\nHost: baidu.com\r\n\r\n" client.send(data.encode()) # receive some data response = client.recv(4096) print(response)
运行结果:
b'HTTP/1.1 200 OK\r\nDate: Sun, 14 Feb 2016 03:34:20 GMT\r\nContent-Type: text/html\r\nContent-Length: 14613\r\nLast-Modified: Wed, 03 Sep 2014 02:48:32 GMT\r\nConnection: Keep-Alive\r\nVary: Accept-Encoding\r\nSet-Cookie: BAIDUID=931D413C5
......
相关文章推荐
- python学习笔记-Day14 -css基础知识-part2
- python之xml文件处理的例子-问题描述及解决方法
- Windows下安装Python PIP
- python编码最佳实践之总结
- python 简单绘图
- python实现百度贴吧爬虫
- Python 中的浮点数
- python交互式文档计算格式
- python动态网页爬取——四六级成绩批量爬取
- Python在Console下显示文本进度条的方法
- Draw Picture With Python Matplotlib
- 【python笔记】python中的list、tuple、set、dict用法简析
- Python安装——Windows
- python2.7.9出现错误_ssl.c:58
- python动态网页批量爬取
- OpenCV Computer Vision with Python第二章笔记
- python出现Non-ASCII character '\xe7' in file ex6.py on line 1, but no encoding declare错误
- python动态网页批量爬取
- 如何使用python爬取csdn博客访问量
- Python在Console下显示文本进度条的方法