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局域网ip扫描示例分享
Apr 03 Python
python通过ftplib登录到ftp服务器的方法
May 08 Python
回调函数的意义以及python实现实例
Jun 20 Python
Python对CSV、Excel、txt、dat文件的处理
Sep 18 Python
在python中bool函数的取值方法
Nov 01 Python
Python利用matplotlib绘制约数个数统计图示例
Nov 26 Python
Python GUI编程学习笔记之tkinter事件绑定操作详解
Mar 30 Python
Python ArgumentParse的subparser用法说明
Apr 20 Python
jupyter notebook oepncv 显示一张图像的实现
Apr 24 Python
Python3-异步进程回调函数(callback())介绍
May 02 Python
python如何写try语句
Jul 14 Python
Scrapy基于scrapy_redis实现分布式爬虫部署的示例
Sep 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读取txt文件组成SQL并插入数据库的代码(原创自Zjmainstay)
2012/07/31 PHP
ThinkPHP使用PHPExcel实现Excel数据导入导出完整实例
2014/07/22 PHP
支持png透明图片的php生成缩略图类分享
2015/02/08 PHP
url地址自动加#号问题说明
2010/08/21 Javascript
js实现在字符串中提取数字
2013/11/05 Javascript
jquery.post用法关于type设置问题补充
2014/01/03 Javascript
JS选项卡动态替换banner图片路径的方法
2015/05/11 Javascript
纯JavaScript实现的分页插件实例
2015/07/14 Javascript
用JavaScript判断CSS浏览器类型前缀的两种方法
2015/10/08 Javascript
理解JS事件循环
2016/01/07 Javascript
CSS或者JS实现鼠标悬停显示另一元素
2016/01/22 Javascript
基于gulp合并压缩Seajs模块的方式说明
2016/06/14 Javascript
vue 路由页面之间实现用手指进行滑动的方法
2018/02/23 Javascript
详解微信小程序支付流程与梳理
2019/07/16 Javascript
Vue+ElementUI项目使用webpack输出MPA的方法
2019/08/27 Javascript
微信小程序按钮点击动画效果的实现
2019/09/04 Javascript
JS立即执行的匿名函数用法分析
2019/11/04 Javascript
JS实现联想、自动补齐国家或地区名称的功能
2020/07/07 Javascript
深度解读vue-resize的具体用法
2020/07/08 Javascript
js实现直播点击飘心效果
2020/08/19 Javascript
python 参数列表中的self 显式不等于冗余
2008/12/01 Python
python3+PyQt5使用数据库窗口视图
2018/04/24 Python
PyQt5实现类似别踩白块游戏
2019/01/24 Python
Python PyCharm如何进行断点调试
2019/07/05 Python
Pytorch 多块GPU的使用详解
2019/12/31 Python
python PIL模块的基本使用
2020/09/29 Python
Python特殊属性property原理及使用方法解析
2020/10/09 Python
使用css3匹配手机屏幕横竖状态
2014/01/27 HTML / CSS
基于HTML5 FileSystem API的使用介绍
2013/04/24 HTML / CSS
New Balance加拿大官方网站:运动鞋和健身服装
2018/11/19 全球购物
个人承诺书格式
2014/06/03 职场文书
语文教研活动总结
2014/07/02 职场文书
2014年社区工会工作总结
2014/12/18 职场文书
七年级上册语文教学计划
2015/01/22 职场文书
2015年财务工作总结范文
2015/03/31 职场文书
《中彩那天》教学反思
2016/02/24 职场文书