代码
import time
import requests
from bs4 import BeautifulSoup
def run():
url = "https://www.xxx.com/yinxiao/zonghe_0_0_0_0_0_0_{page}.html"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/55.0.2883.87 Safari/537.36 "
}
for page in range(1, 51):
res = requests.get(url.format(page=page), headers=headers)
if res.status_code == 200:
getText(res.text)
time.sleep(10)
def getText(html):
soup = BeautifulSoup(html, 'lxml')
for item in soup.select(".b-box > dl"):
audio = item.select("audio > source")
info = item.select(".info > a ")[0].text
audio_src = "https:" + audio[0].get("src")
res = requests.get(audio_src)
res.encoding='utf8'
print(audio_src)
with open("D:\\Soft\\系统美化\\音效\\"+info + ".mp3", "wb") as f:
f.write(res.content)
f.close()
if __name__ == '__main__':
run()
附爬好的资源下载