小爬虫实战

# 2.基于多线程下载如下地址中的抖音视频。
url_list = [
{
'name': 'v1.mp4',
'url': "http://v1-dy.ixigua.com/e94d048065a7ea19efa752b903cdccde/5d81f35d/video/m/220de3e020660a544aab9ebca0dafbc9f791162ea1dd000056846e0f2a80/?a=1128&br=2189&cr=0&cs=0&dr=0&ds=3&er=&l=201909181605180100100580268389B9&lr=aweme&rc=M2RmODN5cDRlcDMzaWkzM0ApZTU6PDw2ODs8Nzo8M2Q3OWdfaWcxY15wZS1fLS1jLS9zc19gL2EzM2AwMmFgYC8zM186Yw%3D%3D",
},
{
'name': 'v2.mp4',
'url': "http://v1-dy.ixigua.com/88ab1df3f3fb520882fb98d03f62c604/5d81f371/video/m/220448eede63429457e86a2b96cb03630e31162e07cb000073d8936c6507/?a=1128&br=989&cr=0&cs=0&dr=0&ds=3&er=&l=201909181605390101560401017489DF&lr=aweme&rc=anQ6cmVudHVwbzMzZmkzM0ApN2k1ZDY5Ozs7N2g8Nzs0NWcuZjUzZHJpcnNfLS0tLTBzczMuXjReNWAxYmAvYV4vMzQ6Yw%3D%3D"
},
{
'name': 'v3.mp4',
'url': "http://v9-dy-z.ixigua.com/1a48e062ebf0f1e475353aa943815d2e/5d81f2fa/video/m/220c28eb8e05f2b48939f070c1c9b55a0931163783c4000097d664ea0813/?a=1128&br=2175&cr=0&cs=0&dr=0&ds=3&er=&l=20190918160348010155048027480B44&lr=aweme&rc=anc7dHRwcWc1bzMzOmkzM0ApPDc2ZDtoOWU2NzxoZmlnZmdfNjNgLm8tZ3NfLS00LS9zc2E0Yy5eLS80XzEuLzAxNDA6Yw%3D%3D"
},
{
'name': 'v4.mp4',
'url': "http://v3-dy.ixigua.com/d6456c86d825b5a42d55ef9c5bc35d11/5d81f381/video/m/220de5a3f7fe37249b0aaf172ef44e32bd411637e8b0000049519634e1d5/?a=1128&br=1629&cr=0&cs=0&dr=0&ds=3&er=&l=20190918160556010008070095762A38&lr=aweme&rc=M2c4aThqOXFubzMzOmkzM0ApN2k6aDlkZTw5NzQ8ODM3M2ducmRybnEvNnFfLS1hLS9zc2IyXi1hXy0yMV80NDE1XjU6Yw%3D%3D"
},
{
'name': 'v5.mp4',
'url': 'https://vd3.bdstatic.com/mda-jihdmqguhb8u9brg/sc/mda-jihdmqguhb8u9brg.mp4?auth_key=1568795444-0-0-9ff92f10bfaa3679c292787abfad151e&bcevod_channel=searchbox_feed&pd=bjh&abtest=all'
}
]

import threading
import requests


def task(url):
rep = requests.get(url['url'])
with open(url['name'], 'wb')as f:
for q in rep.iter_content():
f.write(q)
# f.write(rep.content)


for i in url_list:

t = threading.Thread(target=task, args=(i,))
t.start()
posted @ 2019-09-18 16:10  徐-  阅读(370)  评论(0编辑  收藏  举报