python网络编程之读取网站根目录实例
作者:shichen2014 时间:2021-03-07 03:04:35
本文实例讲述了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,网络,编程
0
投稿
猜你喜欢
Oracle数据库的十种重新启动步骤
2012-07-21 14:58:25
就 CSS3 向 Eric Meyer 请教的 6 个问题
2008-12-29 13:52:00
Javascript 动画初探(原理)
2009-02-06 15:53:00
php获取referer防非法访问
2023-08-20 11:30:58
用 SA FileUp 上传多文件
2008-07-04 13:44:00
先学会为自己做设计
2008-06-01 16:32:00
Golang CSP并发机制及使用模型
2023-09-15 16:13:27
Python使用captcha制作验证码的实现示例
2023-04-16 00:49:35
asp fso创建与删除文件与文件夹
2008-12-31 16:07:00
解决django migrate报错ORA-02000: missing ALWAYS keyword
2023-04-15 14:19:54
Python中easy_install 和 pip 的安装及使用
2023-08-24 13:34:54
Python文件操作,open读写文件,追加文本内容实例
2022-09-03 12:43:17
如何查询Top N及Top(M―N)记录?
2009-11-11 20:03:00
Python字典深浅拷贝与循环方式方法详解
2022-08-04 08:52:25
JSP读取文件实例
2023-07-10 05:16:20
django+mysql的使用示例
2022-10-24 20:34:15
在SQL Server 2005数据库中更改数据架构
2009-01-19 13:06:00
mysql如何跨时区迁移数据
2010-03-25 10:26:00
Go语言实现文件上传
2023-07-08 18:26:38
DW表格应用之细线框的制作
2008-02-03 19:00:00