python实现批量下载

1. response
>>> print response.text
<!doctype html><html><head><title>
Index of /xx_alpha/6.10.10/
</title></head><body>
<h1>Index of /xx_alpha/6.10.10/</h1><hr />
<ul style="list-style: none; font-family: monospace;">
<li><a href="/xx_alpha/">../</a></li>
<li><a href="/xx_alpha/6.10.10/bugreport_1476080344594.log">bugreport_1476080344594.log</a></li>
<li><a href="/xx_alpha/6.10.10/bugreport_1476092074955.log">bugreport_1476092074955.log</a></li>
<li><a href="/xx_alpha/6.10.10/bugreport_1476094857403.log">bugreport_1476094857403.log</a></li>
<li><a href="/xx_alpha/6.10.10/bugreport_1476098137752.log">bugreport_1476098137752.log</a></li>
<li><a href="/xx_alpha/6.10.10/bugreport_1476106510733.log">bugreport_1476106510733.log</a></li>
<li><a href="/xx_alpha/6.10.10/summary_1476080344594.txt">summary_1476080344594.txt</a></li>
<li><a href="/xx_alpha/6.10.10/summary_1476092074955.txt">summary_1476092074955.txt</a></li>
<li><a href="/xx_alpha/6.10.10/summary_1476094857403.txt">summary_1476094857403.txt</a></li>
<li><a href="/xx_alpha/6.10.10/summary_1476098137752.txt">summary_1476098137752.txt</a></li>
<li><a href="/xx_alpha/6.10.10/summary_1476106510733.txt">summary_1476106510733.txt</a></li>
</ul>
<hr />
</body></html>




response = requests.get('http://10.237.14.111:3344/xx_alpha/6.10.10/')
>>> type(response)
<class 'requests.models.Response'>




2. BeautifulSoup
>>> import bs4
>>> soup = bs4.BeautifulSoup(response.text)
>>> type(soup)
<class 'bs4.BeautifulSoup'>


>>> type(soup.select('a[href^=/xx_alpha/6.10.10/bugreport]')[0].attrs.get('href'))
<type 'str'>


3. 怎样查找:函数的定义: help(xxx) 
怎样查找:函数的定义: help(xxx)


4. argsparse
在大部分情况下,这意味着将从命令行中解析出来的属性建立一个简单的 Namespace对象。
>>> parser.parse_args(['--sum', '7', '-1', '42'])
Namespace(accumulate=<built-in function sum>, integers=[7, -1, 42])
ArgumentParser.add_argument(name or flags...[, action][, nargs][, const][, default][, type][, choices][, required][, help][, metavar][, dest])
定义应该如何解析一个命令行参数。下面每个参数有它们自己详细的描述,简单地讲它们是:
name or flags - 选项字符串的名字或者列表,例如foo 或者-f, --foo。
action - 在命令行遇到该参数时采取的基本动作类型。
nargs - 应该读取的命令行参数数目。
const - 某些action和nargs选项要求的常数值。
default - 如果命令行中没有出现该参数时的默认值。
type - 命令行参数应该被转换成的类型。
choices - 参数可允许的值的一个容器。
required - 该命令行选项是否可以省略(只针对可选参数)。
help - 参数的简短描述。
metavar - 参数在帮助信息中的名字。
dest - 给parse_args()返回的对象要添加的属性名称。


parser.add_argument('integers', metavar='N', type=int, nargs='+',
                   help='an integer for the accumulator')
parser.add_argument('--sum', dest='accumulate', action='store_const',
                   const=sum, default=max,
                   help='sum the integers (default: find the max)')


r = requests.get(url) 
with open("code3.zip", "wb") as code:
     code.write(r.content)


str = "Line1-abcdef \nLine2-abc \nLine4-abcd";
print str.split( );
print str.split(' ', 1 );
以上实例输出结果如下:
['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
['Line1-abcdef', '\nLine2-abc \nLine4-abcd']
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值