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实现
Aug 24 Python
Windows下搭建python开发环境详细步骤
Jul 20 Python
Python简单网络编程示例【客户端与服务端】
May 26 Python
Python Web编程之WSGI协议简介
Jul 18 Python
Python将8位的图片转为24位的图片实现方法
Oct 24 Python
Python功能点实现:函数级/代码块级计时器
Jan 02 Python
pyspark操作MongoDB的方法步骤
Jan 04 Python
Python读取指定日期邮件的实例
Feb 01 Python
使用OpenCV-python3实现滑动条更新图像的Canny边缘检测功能
Dec 12 Python
详解python内置模块urllib
Sep 09 Python
python向xls写入数据(包括合并,边框,对齐,列宽)
Feb 02 Python
python树莓派通过队列实现进程交互的程序分析
Jul 04 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
Windows PHP5和Apache的安装与配置
2009/06/08 PHP
PHP自定义函数收代码
2010/08/01 PHP
PHP操作MongoDB GridFS 存储文件的详解
2013/06/20 PHP
php封装一个异常的处理类
2017/06/08 PHP
php的单例模式及应用场景详解
2021/02/27 PHP
细品javascript 寻址,闭包,对象模型和相关问题
2009/04/27 Javascript
JS仿flash上传头像效果实现代码
2011/07/18 Javascript
原生js实现查找/添加/删除/指定元素的class
2013/04/12 Javascript
sogou地图API用法实例教程
2014/09/11 Javascript
js基于cookie方式记住返回页面用法示例
2016/05/27 Javascript
AngularJS封装指令方法详解
2016/12/12 Javascript
jquery UI Datepicker时间控件冲突问题解决
2016/12/16 Javascript
Jquery Easyui自定义下拉框组件使用详解(21)
2020/12/31 Javascript
es7学习教程之fetch解决异步嵌套问题的方法示例
2017/07/21 Javascript
vue路由嵌套的SPA实现步骤
2017/11/06 Javascript
d3.js实现自定义多y轴折线图的示例代码
2018/05/30 Javascript
vue配置接口域名方法总结
2019/05/12 Javascript
vue 动态组件(component :is) 和 dom元素限制(is)用法说明
2020/09/04 Javascript
使用PYTHON创建XML文档
2012/03/01 Python
python多线程用法实例详解
2015/01/15 Python
Windows安装Python、pip、easy_install的方法
2017/03/05 Python
python中子类调用父类函数的方法示例
2017/08/18 Python
pytorch 常用函数 max ,eq说明
2020/06/28 Python
Html5页面上如何禁止手机虚拟键盘弹出
2020/03/19 HTML / CSS
美国第二大团购网站:LivingSocial
2016/07/24 全球购物
瑞典领先的汽车零部件网上零售商:bildelaronline24.se
2017/01/12 全球购物
C++:memset ,memcpy和strcpy的根本区别
2013/04/27 面试题
七年级政治教学反思
2014/02/03 职场文书
企业安全标语
2014/06/07 职场文书
青年志愿者活动方案
2014/08/17 职场文书
护士节活动总结
2014/08/29 职场文书
公司法人授权委托书范本
2014/09/12 职场文书
学习走群众路线心得体会
2014/11/05 职场文书
设备技术员岗位职责
2015/04/11 职场文书
go语言中fallthrough的用法说明
2021/05/06 Golang
分享几个简单MySQL优化小妙招
2022/03/31 MySQL