</pre><p>主要功能:</p><p>登陆一个需要权限的页面,对页面进行解析下载所有列表下的文件到本地目录。</p><pre name="code" class="python">#!/usr/bin/python2.7
#encoding=utf-8
import urllib2
from bs4 import BeautifulSoup
# create a password manager
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
#url = "http://logs.yinonline.com:9080/rawwebyrd/100.10.80.94/2016/04/"
url = "http://logs.yinonline.com:9080/rawwebyrd/100.10.80.96/2016/04/"
username = "jin"
password = "2015@jyl"
# add the username and password to password manager.
password_mgr.add_password(None, url, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
# create "opener" (OpenerDirector instance)
opener = urllib2.build_opener(handler)
# use the opener to fetch a url
opener.open(url)
# Install the opener
urllib2.install_opener(opener)
# Now all calls to
python 批量下载文件
最新推荐文章于 2024-05-01 21:59:49 发布