Python网络编程实用指南
1. 利用urllib和urllib2进行文件下载
在Python中,有许多强大的库可用于网络编程,其中 urllib 和 urllib2 是处理网络资源下载的常用工具。
urllib 库功能强大,可用于从FTP和HTTP服务器下载文件。下面是一个使用 urllib 下载FTP文件的示例代码:
#!/usr/bin/env python
"""
url retriever
Usage:
url_retrieve_urllib.py URL FILENAME
URL:
If the URL is an FTP URL the format should be:
ftp://[username[:password]@]hostname/filename
If you want to use absolute paths to the file to download,
you should make the URL look something like this:
ftp://user:password@host/%2Fpath/to/myfile.txt
Notice the '%2F' at the beginning of the path to the file.
FILENAME:
absolute or relative path to the filename to save downloaded file as
"""
import urllib
impo
超级会员免费看
订阅专栏 解锁全文
3295

被折叠的 条评论
为什么被折叠?



