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 07 Python
讲解Python中的递归函数
Apr 27 Python
python+matplotlib实现礼盒柱状图实例代码
Jan 16 Python
django利用request id便于定位及给日志加上request_id
Aug 26 Python
python复制列表时[:]和[::]之间有什么区别
Oct 16 Python
使用Python进行目录的对比方法
Nov 01 Python
Python元组知识点总结
Feb 18 Python
PyTorch的SoftMax交叉熵损失和梯度用法
Jan 15 Python
TensorFlow梯度求解tf.gradients实例
Feb 04 Python
利用Python如何实时检测自身内存占用
May 09 Python
Django框架安装及项目创建过程解析
Sep 14 Python
用OpenCV进行年龄和性别检测的实现示例
Jan 29 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
PHP中date与gmdate的区别及默认时区设置
2014/05/12 PHP
php导出CSV抽象类实例
2014/09/24 PHP
php检索或者复制远程文件的方法
2015/03/13 PHP
JAVASCRIPT 对象的创建与使用
2021/03/09 Javascript
JavaScript 不只是脚本
2007/05/30 Javascript
javascript实现动态CSS换肤技术的脚本
2007/06/29 Javascript
Javascript获取窗口(容器)的大小及位置参数列举及简要说明
2012/12/09 Javascript
原生js实现半透明遮罩层效果具体代码
2013/06/06 Javascript
javascript 单例模式详解及简单实例
2017/02/14 Javascript
详谈jQuery中使用attr(), prop(), val()获取value的异同
2017/04/25 jQuery
解决vue中修改了数据但视图无法更新的情况
2018/08/27 Javascript
总结javascript三元运算符知识点
2018/09/28 Javascript
浅谈webpack性能榨汁机(打包速度优化)
2019/01/09 Javascript
vue分页器组件编写方法详解
2019/06/28 Javascript
重置Redux的状态数据的方法实现
2019/11/18 Javascript
Vue解析剪切板图片并实现发送功能
2020/02/04 Javascript
介绍Python的Django框架中的QuerySets
2015/04/20 Python
Python 类与元类的深度挖掘 I【经验】
2016/05/06 Python
利用Python读取txt文档的方法讲解
2018/06/23 Python
anaconda中更改python版本的方法步骤
2019/07/14 Python
Python使用matplotlib绘制Logistic曲线操作示例
2019/11/28 Python
Python插件机制实现详解
2020/05/04 Python
在keras下实现多个模型的融合方式
2020/05/23 Python
Python3.9 beta2版本发布了,看看这7个新的PEP都是什么
2020/06/10 Python
python字典的值可以修改吗
2020/06/29 Python
5 分钟读懂Python 中的 Hook 钩子函数
2020/12/09 Python
老生常谈CSS中的长度单位
2016/06/27 HTML / CSS
环法自行车赛官方商店:Le Tour de France
2017/08/27 全球购物
班组长竞聘书
2014/03/31 职场文书
献爱心活动总结
2014/05/07 职场文书
2015年党风廉政建设工作总结
2015/04/09 职场文书
毕业生就业推荐表自我鉴定
2019/06/20 职场文书
详解Python函数print用法
2021/06/18 Python
css filter和getUserMedia的联合使用
2022/02/24 HTML / CSS
集英社今正式宣布 成立游戏公司“集英社Games”
2022/03/31 其他游戏
python运行脚本文件的三种方法实例
2022/06/25 Python