【爬蟲】專案篇-新東方六級聽力音訊

txmmy發表於2024-04-05
import requests,time,random
from fake_useragent import UserAgent


urls=open(r'E:\01pycharm project\網路爬蟲技術\sjj1.txt',encoding='utf-8').read().split()
i=1
for url in urls:
    headers={
        #'User-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36 Edg/100.0.1185.39',
        'user-agent':UserAgent(path=r'./fake_useragent.json').Chrome,
        'Referer':'https://dogwood.xdfsjj.com/',
        'cookie':'_yttoken_=yvpoqsot2il2geyv; _ytuserid_=113498738; zg_did={"did": "17f64e7dcddd63-02f3d4617972ef-56171d58-144000-17f64e7dcdef3f"}; zg_37d62e79d2fa4b8aa0dcfdd95a665ced={"sid": 1650027981031,"updated": 1650027981031,"info": 1650015954242,"superProperty": "{}","platform": "{}","utm": "{}","referrerDomain": "mail.qq.com","zs": 0,"sc": 0,"firstScreen": 1650027981031}',

    }
    req=requests.get(url,headers=headers)
    print(req.status_code)
    with open(r'E:\六級正序\list%d.mp3'%i,'wb') as file:
       file.write(req.content)
       print(i,"下載成功")
       req.close()
    i+=1
    time.sleep(random.randint(1,3))

相關文章