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 从远程服务器下载日志文件的程序
Feb 10 Python
深入讲解Python函数中参数的使用及默认参数的陷阱
Mar 13 Python
Python如何实现MySQL实例初始化详解
Nov 06 Python
Python列表推导式与生成器表达式用法示例
Feb 08 Python
Django 实现购物车功能的示例代码
Oct 08 Python
python 自动重连wifi windows的方法
Dec 18 Python
python中while和for的区别总结
Jun 28 Python
python 字符串的驻留机制及优缺点
Jun 19 Python
Python加速程序运行的方法
Jul 29 Python
Python configparser模块应用过程解析
Aug 14 Python
python+opencv实现车道线检测
Feb 19 Python
Python使用DFA算法过滤内容敏感词
Apr 22 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
js showModalDialog 弹出对话框的简单实例(子窗体)
2014/01/07 Javascript
设置jsf的选择框h:selectOneMenu为不可编辑状态的方法
2014/01/07 Javascript
javascript实现时间格式输出FormatDate函数
2015/01/13 Javascript
JS使用ajax从xml文件动态获取数据显示的方法
2015/03/24 Javascript
vue实现列表的添加点击
2016/12/29 Javascript
在Vue项目中使用jsencrypt.js对数据进行加密传输的方法
2019/04/17 Javascript
详解node登录接口之密码错误限制次数(含代码)
2019/10/25 Javascript
js实现点击生成随机div
2020/01/16 Javascript
vue跳转方式(打开新页面)及传参操作示例
2020/01/26 Javascript
在Vue 中获取下拉框的文本及选项值操作
2020/08/13 Javascript
简单学习Python time模块
2016/04/29 Python
python列表的常用操作方法小结
2016/05/21 Python
Python2.7基于笛卡尔积算法实现N个数组的排列组合运算示例
2017/11/23 Python
python微信跳一跳系列之色块轮廓定位棋盘
2018/02/26 Python
python 字典中文key处理,读取,比较方法
2018/07/06 Python
python控制nao机器人身体动作实例详解
2019/04/29 Python
Python实现平行坐标图的两种方法小结
2019/07/04 Python
pymysql模块的使用(增删改查)详解
2019/09/09 Python
Python MySQL 日期时间格式化作为参数的操作
2020/03/02 Python
python打开文件的方式有哪些
2020/06/29 Python
Django路由层URLconf作用及原理解析
2020/09/24 Python
一款利用纯css3实现的超炫3D表单的实例教程
2014/12/01 HTML / CSS
AmazeUI的下载配置与Helloworld的实现
2020/08/19 HTML / CSS
Square Off美国/加拿大:世界上最聪明的国际象棋棋盘
2018/12/06 全球购物
介绍一下linux文件系统分配策略
2012/11/17 面试题
干部行政关系介绍信
2014/01/17 职场文书
幼儿园国庆节活动方案
2014/02/01 职场文书
文化活动实施方案
2014/03/28 职场文书
合作意向书格式及范文
2014/03/31 职场文书
村长党的群众路线教育实践活动个人对照检查材料
2014/09/23 职场文书
主持人开场白台词
2015/05/29 职场文书
关于观后感的作文
2015/06/18 职场文书
《槐乡的孩子》教学反思
2016/02/20 职场文书
分布式Redis Cluster集群搭建与Redis基本用法
2022/02/24 Redis
基于Python编写简易版的天天跑酷游戏的示例代码
2022/03/23 Python
element tree树形组件回显数据问题解决
2022/08/14 Javascript