This article describes the Python network programming to read the Web site root directory method, share to everyone for your reference.
The implementation method is as follows:
Import socket, sys PORT = * 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
The example running environment for this article is Python2.7.6
The instance returns a list of the root directories of the quux.org
The returned results are as follows:
Iwelcome to Gopher at quux.org! Fake (null) 0i fake (NULL) 0iThis server has a lot of information of historic interest, fake (null) 0ifunny, or just plain Entertaining--all presented in Gopher. Fake (NULL) 0iThere is many mirrors here's rare or valuable files with the fake (null) 0iaim to preserve them in case th EIR host disappears. Please READ fake (NULL) 0i "about this Server" for IMPORTANT NOTES and LEGAL information. Fake (null) 0i fake (null) 00About This server/about this Server.txt gopher.quux.org +1archives/archives Gopher.quux. Org +1books/books gopher.quux.org +1communication/communication gopher.quux.org +ithis directory contains the E Ntire text of the book Fake (null) 0i "We the media:grassroots journalism by the people, for the people" fake (null) 0iby Dan Gillmor in various formats. Fake (null) 0i fake (null) 0iFeel free to download and enjoy. Fake (NULL) 01computers/computers gopher.quux.org +1current issues and Events (Updated APR., 2002)/curreNT gopher.quux.org +1development projects/devel gopher.quux.org +0gopher ' s 10th anniversary/3.0.0.txt Gopher.quux. Org 701Government, Politics, Law, and Conflict/government gopher.quux.org +0how to Help/how to Help.txt GOPHER.QUUX.O RG +1humor and Fun/humor and gopher.quux.org +1index to Quux.org/archives/index gopher.quux.org 701internet/i Nternet gopher.quux.org +1other Gopher servers/software/gopher/servers gopher.quux.org 701people/people Gopher.quux . org. +1reference/reference gopher.quux.org, +1software and Downloads/software gopher.quux.org, +1the gopher Proje Ct/software/gopher gopher.quux.org 700What ' s new/whatsnew.txt gopher.quux.org 70 +
Hopefully this article will help you with Python programming.