python网络编程之读取网站根目录实例

 更新时间:2014年09月30日 09:59:57   投稿:shichen2014  
这篇文章主要介绍了python网络编程之读取网站根目录实例,以quux.org站根目录为例进行了实例分析,代码简单易懂,需要的朋友可以参考下

本文实例讲述了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 Collatz序列实现过程解析

    Python Collatz序列实现过程解析

    这篇文章主要介绍了Python Collatz序列实现过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-10-10
  • python爬虫遇到403错误的问题及解决

    python爬虫遇到403错误的问题及解决

    这篇文章主要介绍了python爬虫遇到403错误的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-02-02
  • Opencv识别图片颜色并绘制轮廓实现代码示例

    Opencv识别图片颜色并绘制轮廓实现代码示例

    这篇文章主要给大家介绍了关于Opencv识别图片颜色并绘制轮廓实现的相关资料,实验代码和现象展示了如何从原始图像中识别和突出显示特定颜色区域,并通过图像处理技术增强识别效果,需要的朋友可以参考下
    2024-12-12
  • Python + Flask 实现简单的验证码系统

    Python + Flask 实现简单的验证码系统

    这篇文章主要介绍了Python + Flask 制作一个简单的验证码系统,本文图文并茂给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-10-10
  • pytorch创建tensor函数详情

    pytorch创建tensor函数详情

    这篇文章主要介绍了pytorch创建tensor函数详情,文章围绕tensor函数的相关自来哦展开详细内容的介绍,需要的小伙伴可以参考一下,希望对你有所帮助
    2022-03-03
  • Django自定义过滤器定义与用法示例

    Django自定义过滤器定义与用法示例

    这篇文章主要介绍了Django自定义过滤器定义与用法,结合实例形式分析了Django自定义过滤器的概念、功能、定义及使用方法,需要的朋友可以参考下
    2018-03-03
  • Tornado Web Server框架编写简易Python服务器

    Tornado Web Server框架编写简易Python服务器

    这篇文章主要为大家详细介绍了Tornado Web Server框架编写简易Python服务器,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-07-07
  • 新手学python应该下哪个版本

    新手学python应该下哪个版本

    在本篇内容中小编给大家整理的是关于新手学python应该下版本的相关知识点,需要的朋友们可以参考学习下。
    2020-06-06
  • Python利用Turtle库绘制一个小老虎

    Python利用Turtle库绘制一个小老虎

    虎年就是要画老虎!本文将通过Python中的Turtle库绘制一个可爱的小老虎,文中的示例代码讲解详细,感兴趣的小伙伴可以了解一下
    2022-02-02
  • 如何表示python中的相对路径

    如何表示python中的相对路径

    在本篇文章里小编给大家分享的是关于python相对路径写法以及相关知识点内容,需要的朋友们可以学习下。
    2020-07-07

最新评论