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代码来绘制彭罗斯点阵的教程
Apr 03 Python
简单介绍Python中利用生成器实现的并发编程
May 04 Python
Python基于更相减损术实现求解最大公约数的方法
Apr 04 Python
python矩阵转换为一维数组的实例
Jun 05 Python
Python分割训练集和测试集的方法示例
Sep 19 Python
TensorFlow查看输入节点和输出节点名称方式
Jan 04 Python
Python图像处理库PIL的ImageFilter模块使用介绍
Feb 26 Python
python输出结果刷新及进度条的实现操作
Jul 13 Python
使用Python pip怎么升级pip
Aug 11 Python
python logging模块的使用详解
Oct 23 Python
Python爬取科目四考试题库的方法实现
Mar 30 Python
Python一行代码实现自动发邮件功能
May 30 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
很温暖很温暖的Lester Young
2021/03/03 冲泡冲煮
PHP使用内置函数file_put_contents写入文件及追加内容的方法
2015/12/07 PHP
详解WordPress中用于合成数组的wp_parse_args()函数
2015/12/18 PHP
深入浅析yii2-gii自定义模板的方法
2016/04/26 PHP
mysql查找删除重复数据并只保留一条实例详解
2016/09/24 PHP
javascript权威指南 学习笔记之null和undefined
2011/09/25 Javascript
jquery增加时编辑jqGrid(实例代码)
2013/11/08 Javascript
将list转换为json失败的原因
2013/12/17 Javascript
使用JavaScript进行进制转换将字符串转换为十进制
2014/09/21 Javascript
如何调试异步加载页面里包含的js文件
2014/10/30 Javascript
javascript每日必学之多态
2016/02/23 Javascript
AngularJS删除路由中的#符号的方法
2016/09/20 Javascript
简单实现jQuery级联菜单
2017/01/09 Javascript
详解微信小程序审核不通过的解决方法
2018/01/17 Javascript
ligerUI的ligerDialog关闭刷新的方法
2019/09/27 Javascript
解决vue-cli输入命令vue ui没效果的问题
2020/11/17 Javascript
python为tornado添加recaptcha验证码功能
2014/02/26 Python
Python实现的随机森林算法与简单总结
2018/01/30 Python
OPENCV去除小连通区域,去除孔洞的实例讲解
2018/06/21 Python
详解基于django实现的webssh简单例子
2018/07/17 Python
Django实现支付宝付款和微信支付的示例代码
2018/07/25 Python
python利用百度AI实现文字识别功能
2018/11/27 Python
python:动态路由的Flask程序代码
2019/11/22 Python
pandas DataFrame 数据选取,修改,切片的实现
2020/04/24 Python
实例讲解CSS3中的border-radius属性
2015/08/18 HTML / CSS
学校七一活动方案
2014/01/19 职场文书
土建专业大学生自荐信范文
2014/04/09 职场文书
《特殊的葬礼》教学反思
2014/04/27 职场文书
人民调解员先进事迹材料
2014/05/08 职场文书
管理标语大全
2014/06/24 职场文书
2014年市场部工作总结
2014/11/25 职场文书
2015年党员承诺书
2015/01/21 职场文书
《观察物体》教学反思
2016/02/17 职场文书
护士年终工作总结不会写?各科护士模板总结
2020/01/02 职场文书
Python爬虫进阶之Beautiful Soup库详解
2021/04/29 Python
matlab xlabel位置的设置方式
2021/05/21 Python