python网络编程之读取网站根目录实例


Posted in Python onSeptember 30, 2014

本文实例讲述了python网络编程之读取网站根目录的方法,分享给大家供大家参考。

具体实现方法如下:

import socket, sys 
 
port = 70 
host = "quux.org" 
filename = "//" 
 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
s.connect((host, port)) 
s.sendall(filename+"\r\n") 
 
while(1): 
  buf = s.recv(2048) 
  if not buf: 
    break 
  sys.stdout.write(buf)

本文实例运行环境为Python2.7.6

该实例会返回quux.org的根目录的列表

返回结果如下:

iWelcome to gopher at quux.org! fake (NULL) 0
i fake (NULL) 0
iThis server has a lot of information of historic interest, fake (NULL) 0
ifunny, or just plain entertaining -- all presented in Gopher. fake (NULL) 0
iThere are many mirrors here of rare or valuable files with the fake (NULL) 0
iaim to preserve them in case their host disappears. PLEASE READ fake (NULL) 0
i"About This Server" FOR IMPORTANT NOTES AND LEGAL INFORMATION. fake (NULL) 0
i fake (NULL) 0
0About This Server /About This Server.txt gopher.quux.org 70 +
1Archives /Archives gopher.quux.org 70 +
1Books /Books gopher.quux.org 70 +
1Communication /Communication gopher.quux.org 70 +
iThis directory contains the entire text of the book fake (NULL) 0
i"We the Media: Grassroots Journalism by the People, for the People" fake (NULL) 0
iby Dan Gillmor in various formats. fake (NULL) 0
i fake (NULL) 0
iFeel free to download and enjoy. fake (NULL) 0
1Computers /Computers gopher.quux.org 70 +
1Current Issues and Events (Updated Apr. 23, 2002) /Current gopher.quux.org 70 +
1Development Projects /devel gopher.quux.org 70 +
0Gopher's 10th Anniversary /3.0.0.txt gopher.quux.org 70
1Government, Politics, Law, and Conflict /Government gopher.quux.org 70 +
0How To Help /How To Help.txt gopher.quux.org 70 +
1Humor and Fun /Humor and Fun gopher.quux.org 70 +
1Index to Quux.Org /Archives/index gopher.quux.org 70
1Internet /Internet gopher.quux.org 70 +
1Other Gopher Servers /Software/Gopher/servers gopher.quux.org 70
1People /People gopher.quux.org 70 +
1Reference /Reference gopher.quux.org 70 +
1Software and Downloads /Software gopher.quux.org 70 +
1The Gopher Project /Software/Gopher gopher.quux.org 70
0What's New /whatsnew.txt gopher.quux.org 70 +

希望本文所述对大家的Python程序设计有所帮助

Python 相关文章推荐
python中使用enumerate函数遍历元素实例
Jun 16 Python
Windows下PyMongo下载及安装教程
Apr 27 Python
Python实现统计代码行的方法分析
Jul 12 Python
Python 处理数据的实例详解
Aug 10 Python
简单谈谈Python的pycurl模块
Apr 07 Python
python获取命令行输入参数列表的实例代码
Jun 23 Python
Django-Rest-Framework 权限管理源码浅析(小结)
Nov 12 Python
Django网络框架之HelloDjango项目创建教程
Jun 06 Python
python字符串,元组,列表,字典互转代码实例详解
Feb 14 Python
Python xmltodict模块安装及代码实例
Oct 05 Python
使用pandas实现筛选出指定列值所对应的行
Dec 13 Python
tensorflow学习笔记之tfrecord文件的生成与读取
Mar 31 Python
python中sets模块的用法实例
Sep 30 #Python
python根据路径导入模块的方法
Sep 30 #Python
python基于xml parse实现解析cdatasection数据
Sep 30 #Python
python中ConfigParse模块的用法
Sep 29 #Python
Python中logging模块的用法实例
Sep 29 #Python
Python基于twisted实现简单的web服务器
Sep 29 #Python
Python学习之asyncore模块用法实例教程
Sep 29 #Python
You might like
基于qmail的完整WEBMAIL解决方案安装详解
2006/10/09 PHP
fetchAll()与mysql_fetch_array()的区别详解
2013/06/05 PHP
在线编辑器中换行与内容自动提取
2009/04/24 Javascript
Grid得到选择行数据的方法总结
2011/01/17 Javascript
javascript写的简单的计算器,内容很多,方法实用,推荐
2011/12/29 Javascript
高性能JavaScript DOM编程(1)
2015/08/11 Javascript
JQuery用户名校验的具体实现
2016/03/18 Javascript
Node.js环境下编写爬虫爬取维基百科内容的实例分享
2016/06/12 Javascript
详解Angular开发中的登陆与身份验证
2016/07/27 Javascript
基于Bootstrap的Metronic框架实现条码和二维码的生成及打印处理操作
2016/08/29 Javascript
JavaScript实现DOM对象选择器
2016/09/24 Javascript
通过源码分析Vue的双向数据绑定详解
2017/09/24 Javascript
NodeJS简单实现WebSocket功能示例
2018/02/10 NodeJs
jQuery each和js forEach用法比较
2019/02/27 jQuery
Vue实现页面添加水印功能
2019/11/09 Javascript
[02:05]2014DOTA2西雅图邀请赛 专访啸天mik夫妻档
2014/07/08 DOTA
python中pycurl库的用法实例
2014/09/30 Python
Python网络爬虫与信息提取(实例讲解)
2017/08/29 Python
windows下python安装pip图文教程
2018/05/25 Python
对pandas中to_dict的用法详解
2018/06/05 Python
带你认识Django
2019/01/15 Python
Python基于opencv调用摄像头获取个人图片的实现方法
2019/02/21 Python
python2 中 unicode 和 str 之间的转换及与python3 str 的区别
2019/07/25 Python
python3列表删除大量重复元素remove()方法的问题详解
2021/01/04 Python
plt.figure()参数使用详解及运行演示
2021/01/08 Python
python 三种方法提取pdf中的图片
2021/02/07 Python
CSS3教程(5):网页背景图片
2009/04/02 HTML / CSS
纯css3实现的动画按钮的实例教程
2014/11/17 HTML / CSS
Sephora丝芙兰菲律宾官方网站:购买化妆品和护肤品
2017/04/05 全球购物
本科生职业生涯规划书范文
2014/01/21 职场文书
初中高效课堂实施方案
2014/02/26 职场文书
规划编制实施方案
2014/03/15 职场文书
党的群众路线教育实践活动个人整改方案
2014/09/21 职场文书
乡镇镇长个人整改措施
2014/10/01 职场文书
CSS3实现的侧滑菜单
2021/04/27 HTML / CSS
Android开发手册自定义Switch开关按钮控件
2022/06/10 Java/Android