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解释器理解Python中的字节码
Apr 01 Python
简介二分查找算法与相关的Python实现示例
Aug 26 Python
实例讲解Python中SocketServer模块处理网络请求的用法
Jun 28 Python
Python排序搜索基本算法之插入排序实例分析
Dec 11 Python
浅析Python pandas模块输出每行中间省略号问题
Jul 03 Python
pygame游戏之旅 添加键盘按键的方法
Nov 20 Python
解决python中无法自动补全代码的问题
Dec 04 Python
对python中词典的values值的修改或新增KEY详解
Jan 20 Python
Python字符串通过'+'和join函数拼接新字符串的性能测试比较
Mar 05 Python
Python 使用 Pillow 模块给图片添加文字水印的方法
Aug 30 Python
pygame实现俄罗斯方块游戏(AI篇2)
Oct 29 Python
python实现用户名密码校验
Mar 18 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
收听困难?教您超简便短波广播抗干扰方法!
2021/03/01 无线电
php数组中包含中文的排序方法
2014/06/03 PHP
php线性表的入栈与出栈实例分析
2015/06/12 PHP
Maps Javascript
2007/01/22 Javascript
js left,right,mid函数
2008/06/10 Javascript
在JQuery dialog里的服务器控件 事件失效问题
2010/12/08 Javascript
精心挑选的15个jQuery下拉菜单制作教程
2012/06/15 Javascript
js实现两个值相加alert出来精确到指定位
2013/09/25 Javascript
js中取得变量绝对值的方法
2015/01/03 Javascript
JS显示表格内指定行html代码的方法
2015/03/31 Javascript
JavaSciprt中处理字符串之sup()方法的使用教程
2015/06/08 Javascript
3个可以改善用户体验的AngularJS指令介绍
2015/06/18 Javascript
学习JavaScript设计模式(单例模式)
2015/11/26 Javascript
javascript实现自动填写表单实例简析
2015/12/02 Javascript
javascript嵌套函数和在函数内调用外部函数的区别分析
2016/01/31 Javascript
详解JavaScript中数组和字符串的lastIndexOf()方法使用
2016/03/13 Javascript
jQuery文字横向滚动效果的实现代码
2016/05/31 Javascript
jQuery ajax应用总结
2016/06/02 Javascript
js判断是否是手机页面
2017/03/17 Javascript
详解Angular 4.x NgTemplateOutlet
2017/05/24 Javascript
AngularJS实现表单元素值绑定操作示例
2017/10/11 Javascript
VUE v-model表单数据双向绑定完整示例
2019/01/21 Javascript
微信小程序学习笔记之目录结构、基本配置图文详解
2019/03/28 Javascript
微信小程序导入Vant报错VM292:1 thirdScriptError的解决方法
2019/08/01 Javascript
微信小程序左右滚动公告栏效果代码实例
2019/09/16 Javascript
JS数组方法slice()用法实例分析
2020/01/18 Javascript
Vue 打包的静态文件不能直接运行的原因及解决办法
2020/11/19 Vue.js
Python+OpenCV检测灯光亮点的实现方法
2020/11/02 Python
python hmac模块验证客户端的合法性
2020/11/07 Python
Tarte Cosmetics官网:美国最受欢迎的化妆品公司之一
2017/08/24 全球购物
viagogo波兰票务平台:演唱会、体育比赛、戏剧门票
2018/04/23 全球购物
物流管理专业大学生自荐信
2013/10/04 职场文书
后勤部长岗位职责
2013/12/14 职场文书
2014年党员自我评议(5篇)
2014/09/12 职场文书
电影建党伟业观后感
2015/06/01 职场文书
大学生见习总结报告
2015/06/24 职场文书