鱼C论坛

 找回密码
 立即注册
查看: 2727|回复: 0

[作品展示] 用Python制作的铃声下载小工具

[复制链接]
发表于 2020-9-10 22:47:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
直接上代码....
  1. import requests
  2. import os
  3. from bs4 import BeautifulSoup
  4. import time


  5. def get_url(url):
  6.     headers = {
  7.         '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'
  8.     }
  9.     res = requests.get(url, headers=headers)
  10.     soup = BeautifulSoup(res.text, 'html.parser')
  11.     items = soup.select('div.b-box')
  12.     urls = ['https:' + item['src'] for item in items[0].select('source')]  # 音乐地址
  13.     names = [state for n in items[0].select('dt.info') for state in n.find('a')]  # 音乐名称
  14.     path = '搞怪铃声'
  15.     if not os.path.exists(path):  # 设置存放路径
  16.         os.mkdir(path)
  17.     for name, link in zip(names, urls):
  18.         with open(r'{}\{}.mp3'.format(path, name), 'wb') as file:  # 写入数据
  19.             res = requests.get(link)
  20.             print(name, '下载成功')
  21.             file.write(res.content)


  22. link = 'https://www.tukuppt.com/yinxiao/zonghe_0_0_0_0_0_0_{}.html'  # 目标地址
  23. page = int(input('请输入下载的页数:'))
  24. urls = [link.format(i) for i in range(1, page + 1)]

  25. for url in urls:
  26.     get_url(url)
  27.     time.sleep(1)  # 休息1秒,以免被封
复制代码
music.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-27 02:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表