python网络编程之读取网站根目录实例
程序员文章站
2023-10-19 17:51:17
本文实例讲述了python网络编程之读取网站根目录的方法,分享给大家供大家参考。
具体实现方法如下:
import socket, sys
port...
本文实例讲述了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程序设计有所帮助
下一篇: DSAPI WIN7风格