Python network programming read Web site root directory instance _python

Source: Internet
Author: User
Tags gopher

This article describes the Python network programming to read the site root directory method, share for everyone to reference.

The implementation methods are as follows:

Import socket, sys 
 
port = " 
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) 

The instance of this article runs in Python2.7.6 environment

This instance returns a list of quux.org's root directories

The returned results are as follows:

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 pl Ain entertaining-all presented in Gopher. Fake (NULL) 0 IThere are many mirrors here is 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 + 1archives/archives Gopher.qu  ux.org + 1books/books gopher.quux.org + 1communication/communication gopher.quux.org-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 + 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 1Government, Politics, conflict/government gopher.quux.org + 0How to Help/how to Help.txt gopher.quux.org + 1Humor and Fun/humor and Fun gopher.quux.org + 1Index to Quux.org/archives/index Gophe r.quux.org 1internet/internet gopher.quux.org + 1Other Gopher servers/software/gopher/servers gopher.quux.org 70 1 People/people gopher.quux.org + 1reference/reference gopher.quux.org + 1Software and Downloads/software Gopher.qu

 ux.org + 1The Gopher project/software/gopher gopher.quux.org 0What ' s new/whatsnew.txt gopher.quux.org 70 +

Hopefully this article will help you with your Python programming

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.