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快速排序代码实例
Nov 21 Python
python中for语句简单遍历数据的方法
May 07 Python
Python实现队列的方法
May 26 Python
Python中将字典转换为XML以及相关的命名空间解析
Oct 15 Python
python黑魔法之编码转换
Jan 25 Python
深入浅析python中的多进程、多线程、协程
Jun 22 Python
python opencv读mp4视频的实例
Dec 07 Python
python提取包含关键字的整行数据方法
Dec 11 Python
Java文件与类动手动脑实例详解
Nov 10 Python
ffmpeg+Python实现B站MP4格式音频与视频的合并示例代码
Oct 21 Python
python3操作redis实现List列表实例
Aug 04 Python
python可视化之颜色映射详解
Sep 15 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
PHPUnit安装及使用示例
2014/10/29 PHP
PHP魔术方法的使用示例
2015/06/23 PHP
php实现的一段简单概率相关代码
2016/05/30 PHP
PHP用continue跳过本次循环中剩余代码的注意点
2017/06/27 PHP
PHP基于面向对象实现的留言本功能实例
2018/04/04 PHP
一行代码告别document.getElementById
2012/06/01 Javascript
不依赖Flash和任何JS库实现文本复制与剪切附源码下载
2015/10/09 Javascript
Javascript原型链的原理详解
2016/01/05 Javascript
BootStrap响应式导航条实例介绍
2016/05/06 Javascript
JavaScript的new date等日期函数在safari中遇到的坑
2016/10/24 Javascript
微信小程序  生命周期详解
2016/10/27 Javascript
Bootstrap栅格系统的使用和理解2
2016/12/14 Javascript
jQuery实现鼠标经过显示动画边框特效
2017/03/24 jQuery
详解使用Node.js 将txt文件转为Excel文件
2017/07/05 Javascript
JavaScript中各数制转换全面总结
2017/08/21 Javascript
Vue中之nextTick函数源码分析详解
2017/10/17 Javascript
基于nodejs的雪碧图制作工具的示例代码
2018/11/05 NodeJs
vue自定义指令之面板拖拽的实现
2019/04/14 Javascript
js+canvas实现画板功能
2020/09/13 Javascript
Vue实现Header渐隐渐现效果的实例代码
2020/11/05 Javascript
JS闭包原理及其使用场景解析
2020/12/03 Javascript
Python学习笔记_数据排序方法
2014/05/22 Python
在Python中测试访问同一数据的竞争条件的方法
2015/04/23 Python
Python序列循环移位的3种方法推荐
2018/04/09 Python
Python使用selenium实现网页用户名 密码 验证码自动登录功能
2018/05/16 Python
python3 tcp的粘包现象和解决办法解析
2019/12/09 Python
Python logging日志库空间不足问题解决
2020/09/14 Python
英国景点门票网站:attractiontix
2019/08/27 全球购物
春节联欢晚会主持词范文
2014/03/24 职场文书
2014年党员承诺书范文
2014/05/20 职场文书
党支部承诺书
2015/01/20 职场文书
OpenCV-Python直方图均衡化实现图像去雾
2021/06/07 Python
Python OpenCV形态学运算示例详解
2022/04/07 Python
Redis中key的过期删除策略和内存淘汰机制
2022/04/12 Redis
微软官方消息,在 2023 年 4 月 11 日之后微软将不再为 Office 2013 和 Skype for Business 2015 提供安全更新
2022/04/21 数码科技
Vue Element plus使用方法梳理
2022/12/24 Vue.js