python网络编程之读取网站根目录实例
作者:shichen2014 发布时间:2021-03-07 03:04:35
标签:python,网络,编程
本文实例讲述了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程序设计有所帮助
0
投稿
猜你喜欢
- Line plotsAxes3D.plot(xs, ys, *args, **kwargs)绘制2D或3D数据参数描述xs, ysX轴,Y轴
- 瞬间设计是什么?良好的用户体验,全在于那些完美的瞬间。在第一个瞬间,假设当一位用户从购物搜索结果页面跳转到某个店铺的时候,他此刻可能是想看看
- 1、流程控制流程控制在编程语言中是最伟大的发明了,因为有了它,你可以通过很简单的流程描述来表达很复杂的逻辑。流程控制包含分三大类:条件判断,
- 语法: text-overflow : clip | ellipsis 参数: clip : 不显示省略标记(...),而是简单的裁切 el
- 在前面的DRF系列教程中,我们以博客为例介绍了序列化器, 使用基于类的视图APIView和ModelViewSet开发了针对文章资源进行增删
- 五子棋游戏相信大部分人都玩过,今天我们用python来实现一次具体代码可以访问我的GitHub地址获取构建五子棋棋盘from collect
- 本文实例为大家分享了python实现登录与注册系统的具体代码,供大家参考,具体内容如下实现功能1.调用文本文件里的用户信息2.可以将注册信息
- 看到这张照片,我们一眼能够看到天宏(图中这位UED俊男)的眼睛。我们能从他的表情里读出一些他的性格。一张好的摄影作品,最重要的一点,就是这个
- 基本思路使用GDAL创建Shapefile数据的基本步骤如下:使用osgeo.ogr.Driver的CreateDataSource()方法
- 【问】使用FCKeditor添加文章时,在文章最后多了逗号。【答】此情况发生在asp环境中。在asp里对于 提交的表单信息中如果有相同nam
- MapPathMapPath 方法将指定的相对或虚拟路径映射到服务器上相应的物理目录上。语法Server.MapPath( Path ) 参
- 我想把本篇作为css基础教程的序曲,从今天开始翻译和整理我从设计网页以来所学到的css基础知识。本教程会分成N个部分,单独发表,其间可能会插
- 最近看到一个内部项目的插件加载机制,非常赞。当然这里说的插件并不是指的golang原生的可以在buildmode中加载指定so文件的那种加载
- 程序能实现什么a.完成gap值的自定义输入以及两条需比对序列的输入b.完成得分矩阵的计算及输出c.输出序列比对结果d.使用matplotli
- 本文实例讲述了Python提示[Errno 32]Broken pipe导致线程crash错误解决方法。分享给大家供大家参考。具体方法如下:
- 分区表的概念 分区致力于解决支持极大表和索引的关键问题。它采用他们分解成较小和易于管理的称为分区的片(piece)的方法。一旦分区被定义,S
- 因工作需要,最近在学习使用python来解析各种文件,包括xmind,xml,excel,csv等等。在学习python解析XML的时候看到
- 还是决定冠上ajax的头衔,毕竟很多人会用这个关键词搜索。虽然我认为这只是个炒作的概念,不过不得不承认ajax叫起来要方便多了。ajax的意
- 用下列代码可在控制弹出NTLM验证窗口:<% Response.Status = "401 Unauthorized&quo
- 在对跨多个表格的数据进行组合时,有时很难搞清楚要使用哪一个SQL句法。我将在这里对将多个表格中的查询合并至单一声明中的常用方式进行阐述。在这