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代码检查工具pylint 让你的python更规范
Sep 05 Python
几个提升Python运行效率的方法之间的对比
Apr 03 Python
python3.4控制用户输入与输出的方法
Oct 17 Python
python中ImageTk.PhotoImage()不显示图片却不报错问题解决
Dec 06 Python
Python使用__new__()方法为对象分配内存及返回对象的引用示例
Sep 20 Python
kafka监控获取指定topic的消息总量示例
Dec 23 Python
三个python爬虫项目实例代码
Dec 28 Python
Python try except异常捕获机制原理解析
Apr 18 Python
Python scrapy爬取小说代码案例详解
Jul 09 Python
Python3+Appium安装及Appium模拟微信登录方法详解
Feb 16 Python
教你如何使用Python开发一个钉钉群应答机器人
Jun 21 Python
python解析json数据
Apr 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
盘点被央视点名过的日本动画电影 一部比一部强
2020/03/08 日漫
php开启安全模式后禁用的函数集合
2011/06/26 PHP
php魔术方法与魔术变量、内置方法与内置变量的深入分析
2013/06/03 PHP
php连接odbc数据源并保存与查询数据的方法
2014/12/24 PHP
PHP实现通用alert函数的方法
2015/03/11 PHP
php给一组指定关键词添加span标签的方法
2015/03/31 PHP
php集成动态口令认证
2016/07/21 PHP
PHP实现权限管理功能示例
2017/09/22 PHP
php中各种定义变量的方法小结
2017/10/18 PHP
JS鼠标事件大全 推荐收藏
2011/11/01 Javascript
按下Enter焦点移至下一个控件的实现js代码
2013/12/11 Javascript
jquery统计用户选中的复选框的个数
2014/06/06 Javascript
AngularJS入门心得之directive和controller通信过程
2016/01/25 Javascript
jquery单击事件和双击事件冲突解决方案
2016/03/02 Javascript
javascirpt实现2个iframe之间传值的方法
2016/06/30 Javascript
关于JavaScript限制字数的输入框的那些事
2016/08/14 Javascript
angularjs实现首页轮播图效果
2017/04/14 Javascript
node.js中express中间件body-parser的介绍与用法详解
2017/05/23 Javascript
浅谈通过JS拦截 pushState和replaceState事件
2017/07/21 Javascript
详解基于vue的服务端渲染框架NUXT
2018/06/20 Javascript
vue.js实现的经典计算器/科学计算器功能示例
2018/07/11 Javascript
countUp.js实现数字动态变化效果
2019/10/17 Javascript
vuex刷新后数据丢失的解决方法
2020/10/18 Javascript
js 压缩图片的示例(只缩小体积,不更改图片尺寸)
2020/10/21 Javascript
[42:56]VGJ.S vs Serenity 2018国际邀请赛小组赛BO2 第二场 8.19
2018/08/21 DOTA
轻松实现TensorFlow微信跳一跳的AI
2018/01/05 Python
详解Python字典的操作
2019/03/04 Python
详解Python 函数如何重载?
2019/04/23 Python
Python的轻量级ORM框架peewee使用教程
2021/02/05 Python
CSS教程:CSS3圆角属性
2009/04/02 HTML / CSS
假面舞会策划方案
2014/05/29 职场文书
高中班级口号
2014/06/09 职场文书
爱牙日活动总结
2014/08/29 职场文书
机票销售员态度不好检讨书
2014/09/27 职场文书
2014红色之旅心得体会
2014/10/07 职场文书
springboot创建的web项目整合Quartz框架的项目实践
2022/06/21 Java/Android