Swds 发布的文章

import json, time, requests, re
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0','Accept':'*/*'}
def xyp(id='210'):
    url='http://xx.com/audio_'+id+'.html'
    req = requests.get(url, timeout = 20)
    req.encoding = 'utf-8'
    smp3=re.search('h/aaa/bb/(.+).mp3', req.text).group(1)
    result='http://xx2.com/data1/h/aaa/bb/'+smp3+'.mp3'
    print(result)
    res = requests.get(result)
    with open(r'/root/xyp/'+smp3+'.mp3', 'ab') as file:
        file.write(res.content)
        file.flush()
    return 1
for i in range(1,1286):
    xyp(str(i))