資源簡介
import requests
from lxml import etree
url = 'https://music.163.com/playlist?id=2409342460'
base_url = 'https://music.163.com/song/media/outer/url?id='
html_str = requests.get(url).text
dom = etree.HTML(html_str)
song_ids = dom.xpath('//a[contains(@href,"/song?")]/@href')
song_names = dom.xpath('//a[contains(@href,"/song?")]/text()')
for song_id,song_name in zip(song_ids,song_names):
count_id = song_id.strip('/song?id=')
if('$' in count_id) == False:
mp3_url = base_url count_id '.mp3'
print(mp3_url)
mp3 = requests.get(mp3_url).content
str = '%s.mp3'%song_name
print(str)
with open(str,'wb') as file:
file.write(mp3)
from lxml import etree
url = 'https://music.163.com/playlist?id=2409342460'
base_url = 'https://music.163.com/song/media/outer/url?id='
html_str = requests.get(url).text
dom = etree.HTML(html_str)
song_ids = dom.xpath('//a[contains(@href,"/song?")]/@href')
song_names = dom.xpath('//a[contains(@href,"/song?")]/text()')
for song_id,song_name in zip(song_ids,song_names):
count_id = song_id.strip('/song?id=')
if('$' in count_id) == False:
mp3_url = base_url count_id '.mp3'
print(mp3_url)
mp3 = requests.get(mp3_url).content
str = '%s.mp3'%song_name
print(str)
with open(str,'wb') as file:
file.write(mp3)
代碼片段和文件信息
import?requests
from?lxml?import?etree
url?=?‘https://music.163.com/playlist?id=2409342460‘
base_url?=?‘https://music.163.com/song/media/outer/url?id=‘
html_str?=?requests.get(url).text
dom?=?etree.HTML(html_str)
song_ids?=?dom.xpath(‘//a[contains(@href“/song?“)]/@href‘)
song_names?=?dom.xpath(‘//a[contains(@href“/song?“)]/text()‘)
for?song
- 上一篇:python數據結構
- 下一篇:打磚塊
評論
共有 條評論