|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
直接上代码....
- import requests
- import os
- from bs4 import BeautifulSoup
- import time
- def get_url(url):
- headers = {
- 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36'
- }
- res = requests.get(url, headers=headers)
- soup = BeautifulSoup(res.text, 'html.parser')
- items = soup.select('div.b-box')
- urls = ['https:' + item['src'] for item in items[0].select('source')] # 音乐地址
- names = [state for n in items[0].select('dt.info') for state in n.find('a')] # 音乐名称
- path = '搞怪铃声'
- if not os.path.exists(path): # 设置存放路径
- os.mkdir(path)
- for name, link in zip(names, urls):
- with open(r'{}\{}.mp3'.format(path, name), 'wb') as file: # 写入数据
- res = requests.get(link)
- print(name, '下载成功')
- file.write(res.content)
- link = 'https://www.tukuppt.com/yinxiao/zonghe_0_0_0_0_0_0_{}.html' # 目标地址
- page = int(input('请输入下载的页数:'))
- urls = [link.format(i) for i in range(1, page + 1)]
- for url in urls:
- get_url(url)
- time.sleep(1) # 休息1秒,以免被封
复制代码 |
-
|