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中format()函数的简单使用教程
Mar 14 Python
Python中的二维数组实例(list与numpy.array)
Apr 13 Python
python设置值及NaN值处理方法
Jul 03 Python
Python用于学习重要算法的模块pygorithm实例浅析
Aug 16 Python
Django 自定义权限管理系统详解(通过中间件认证)
Mar 11 Python
记录模型训练时loss值的变化情况
Jun 16 Python
Keras自定义实现带masking的meanpooling层方式
Jun 16 Python
python使用requests库爬取拉勾网招聘信息的实现
Nov 20 Python
python 如何用terminal输入参数
May 25 Python
从np.random.normal()到正态分布的拟合操作
Jun 02 Python
总结Python使用过程中的bug
Jun 18 Python
Python初学者必备的文件读写指南
Jun 23 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:风雨欲来 路在何方?
2006/10/09 PHP
允许phpmyadmin空密码登录的配置方法
2011/05/29 PHP
php _autoload自动加载类与机制分析
2012/02/10 PHP
php函数间的参数传递(值传递/引用传递)
2013/09/23 PHP
thinkphp文件引用与分支结构用法实例
2014/11/26 PHP
php求一个网段开始与结束IP地址的方法
2015/07/09 PHP
Zend Framework动作助手Url用法详解
2016/03/05 PHP
php 判断页面或图片是否经过gzip压缩的方法
2017/04/05 PHP
Prototype使用指南之array.js
2007/01/10 Javascript
实现超用户体验 table排序javascript实现代码
2009/06/22 Javascript
将json对象转换为字符串的方法
2014/02/20 Javascript
JavaScript格式化日期时间的方法和自定义格式化函数示例
2014/04/04 Javascript
jQuery异步加载数据并添加事件示例
2014/08/24 Javascript
一个简单的JavaScript Map实例(分享)
2016/08/03 Javascript
jQuery实现的表格展开伸缩效果实例
2016/09/07 Javascript
jQuery实现表格与ckeckbox的全选与单选功能
2016/11/24 Javascript
详解Bootstrap各式各样的按钮(推荐)
2016/12/13 Javascript
jquery mobile移动端幻灯片滑动切换效果
2020/04/15 Javascript
SeaJS中use函数用法实例分析
2017/10/10 Javascript
javascript用rem来做响应式开发
2018/01/13 Javascript
Electron 打包问题:electron-builder 下载各种依赖出错(推荐)
2020/07/09 Javascript
Element Breadcrumb 面包屑的使用方法
2020/07/26 Javascript
python清除字符串里非字母字符的方法
2015/07/02 Python
用python一行代码得到数组中某个元素的个数方法
2019/01/28 Python
Python3中_(下划线)和__(双下划线)的用途和区别
2019/04/26 Python
Python多进程入门、分布式进程数据共享实例详解
2019/06/03 Python
Python中的 sort 和 sorted的用法与区别
2019/08/10 Python
Python 调用 Windows API COM 新法
2019/08/22 Python
Scrapy框架基本命令与settings.py设置
2020/02/06 Python
Python 窗体(tkinter)下拉列表框(Combobox)实例
2020/03/04 Python
python爬虫学习笔记之Beautifulsoup模块用法详解
2020/04/09 Python
python安装第三方库如xlrd的方法
2020/10/31 Python
巴黎一票通:The Paris Pass
2018/02/10 全球购物
毕业生自荐信范文
2015/03/05 职场文书
鸦片战争观后感
2015/06/09 职场文书
光荣之路观后感
2015/06/12 职场文书