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 Django模板的使用方法(图文)
Nov 04 Python
python自动zip压缩目录的方法
Jun 28 Python
Python字典数据对象拆分的简单实现方法
Dec 05 Python
python使用socket创建tcp服务器和客户端
Apr 12 Python
pandas将numpy数组写入到csv的实例
Jul 04 Python
python 返回列表中某个值的索引方法
Nov 07 Python
使用python opencv对目录下图片进行去重的方法
Jan 12 Python
python打包成so文件过程解析
Sep 28 Python
python多维数组分位数的求取方式
Mar 03 Python
Pandas替换及部分替换(replace)实现流程详解
Oct 12 Python
Python txt文件如何转换成字典
Nov 03 Python
python中random模块详解
Mar 01 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下常用正则表达式整理
2010/10/26 PHP
Symfony2之session与cookie用法小结
2016/03/18 PHP
PHP 二维array转换json的实例讲解
2018/08/21 PHP
JavaScript延迟加载
2021/03/09 Javascript
javascript 获取所有id中包含某关键字的控件的实现代码
2010/11/25 Javascript
Json和Jsonp理论实例代码详解
2013/11/15 Javascript
JavaScript阻止回车提交表单的方法
2015/12/30 Javascript
JS无缝滚动效果实现方法分析
2016/12/21 Javascript
HTML5 js实现拖拉上传文件功能
2020/11/20 Javascript
微信小程序图表插件(wx-charts)实例代码
2017/01/17 Javascript
前端开发必知的15个jQuery小技巧
2017/01/22 Javascript
Vue.js鼠标悬浮更换图片功能
2017/05/17 Javascript
requirejs + vue 项目搭建详解
2017/06/16 Javascript
bing Map 在vue项目中的使用详解
2018/04/09 Javascript
vue :src 文件路径错误问题的解决方法
2018/05/15 Javascript
JavaScript中click和onclick本质区别与用法分析
2018/06/07 Javascript
Vue+webpack+Element 兼容问题总结(小结)
2018/08/16 Javascript
javascript判断一个变量是数组还是对象
2019/04/10 Javascript
vue前后分离调起微信支付
2019/07/29 Javascript
vue项目初始化到登录login页面的示例
2019/10/31 Javascript
Python中使用ConfigParser解析ini配置文件实例
2014/08/30 Python
python基础教程之五种数据类型详解
2017/01/12 Python
pyqt5简介及安装方法介绍
2018/01/31 Python
python如何为被装饰的函数保留元数据
2018/03/21 Python
Python3批量生成带logo的二维码方法
2019/06/24 Python
Python 仅获取响应头, 不获取实体的实例
2019/08/21 Python
大学生入党自我鉴定
2013/10/31 职场文书
后勤部长岗位职责
2013/12/14 职场文书
50岁生日感言
2014/01/23 职场文书
施工安全责任书
2014/04/14 职场文书
《雨点儿》教学反思
2014/04/14 职场文书
大专毕业生求职信
2014/07/05 职场文书
委托公证书样本
2015/01/23 职场文书
《赵州桥》教学反思
2016/02/17 职场文书
人生感悟经典句子
2019/08/20 职场文书
浅谈如何提高PHP代码质量之端到端集成测试
2021/05/28 PHP