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实现带声音的摩斯码翻译实现方法
May 20 Python
Python实现将绝对URL替换成相对URL的方法
Jun 28 Python
python编写弹球游戏的实现代码
Mar 12 Python
Python cookbook(数据结构与算法)找出序列中出现次数最多的元素算法示例
Mar 15 Python
python实战之实现excel读取、统计、写入的示例讲解
May 02 Python
Python列表切片操作实例总结
Feb 19 Python
django-rest-framework 自定义swagger过程详解
Jul 18 Python
Python中bisect的使用方法
Dec 31 Python
python继承threading.Thread实现有返回值的子类实例
May 02 Python
详解tensorflow2.x版本无法调用gpu的一种解决方法
May 25 Python
python 6行代码制作月历生成器
Sep 18 Python
Django vue前后端分离整合过程解析
Nov 20 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开发过程中常用函数收藏
2009/12/14 PHP
PHP 实现代码复用的一个方法 traits新特性
2015/02/22 PHP
php中删除数组的第一个元素和最后一个元素的函数
2015/03/07 PHP
php保存任意网络图片到服务器的方法
2015/04/14 PHP
CodeIgniter分页类pagination使用方法示例
2016/03/28 PHP
Javascript attachEvent传递参数的办法
2009/12/14 Javascript
让浏览器非阻塞加载javascript的几种方法小结
2011/04/25 Javascript
获取鼠标在div中的相对位置的实现代码
2013/12/30 Javascript
JavaScript制作的可折叠弹出式菜单示例
2014/04/04 Javascript
jQuery实现鼠标双击Table单元格变成文本框及输入内容后更新到数据库的方法
2015/11/25 Javascript
详解vue事件对象、冒泡、阻止默认行为
2017/03/20 Javascript
Bootstrap标签页(Tab)插件使用方法
2017/03/21 Javascript
基于JS实现网页中的选项卡(两种方法)
2017/06/16 Javascript
引入JavaScript时alert弹出框显示中文乱码问题
2017/09/16 Javascript
React操作真实DOM实现动态吸底部的示例
2017/10/23 Javascript
浅谈VUE单页应用首屏加载速度优化方案
2018/08/28 Javascript
每个 JavaScript 工程师都应懂的33个概念
2018/10/22 Javascript
JS函数动态传递参数的方法分析【基于arguments对象】
2019/06/05 Javascript
vue 开发之路由配置方法详解
2019/12/02 Javascript
JS前端广告拦截实现原理解析
2020/02/17 Javascript
[03:01]完美盛典趣味短片 DOTA2年度最佳&拉胯英雄
2019/12/07 DOTA
[01:06:54]DOTA2-DPC中国联赛 正赛 SAG vs DLG BO3 第二场 2月28日
2021/03/11 DOTA
利用QT写一个极简单的图形化Python闹钟程序
2015/04/07 Python
Python实现的用户登录系统功能示例
2018/02/05 Python
Python实现的括号匹配判断功能示例
2018/08/25 Python
Python改变对象的字符串显示的方法
2020/08/01 Python
学生档案自我鉴定
2013/10/07 职场文书
小学生爱国演讲稿
2014/04/25 职场文书
槐乡的孩子教学反思
2014/04/27 职场文书
服务标兵事迹材料
2014/05/04 职场文书
励志演讲稿500字
2014/08/21 职场文书
法定代表人证明书
2014/11/28 职场文书
云冈石窟导游词
2015/02/04 职场文书
4S店销售内勤岗位职责
2015/04/13 职场文书
2016年元旦致辞
2015/08/01 职场文书
php+laravel 扫码二维码签到功能
2021/05/15 PHP