您的位置:首页 > 编程语言 > Python开发

python中urllib下载软件包

2013-11-14 11:01 162 查看
#-------------------------------------------------------------------------------
# Name:        urllib 模块
# Purpose:
#
# Author:      quan
#
# Created:     15/08/2013
# Copyright:   (c) quan 2013
# Licence:     <your licence>
#-------------------------------------------------------------------------------

import urllib

#
str1  = """<a class="postroll" title="Download Windows 64-bit" href="http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2.4.5.zip" data-postroll="/dr/downloads.mongodb.org/win32/mongodb-win32-x86_64-2.4.5.zip/download"> 64-bit </a>"""

#查找到网页中的带有title的标签
title = str1.find(r'title=')
print title
#表示从title向后面查找
href = str1.find(r'href=',title)
print href
#表示从href向后面查找
html = str1.find(r'.zip',href)
print html

#整合url要读取文章的路径
url = str1[href + 6:html+4]
print url

urllib.urlretrieve(url,'D:\\mongodb-win32-x86_64-2.4.5.zip')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: