马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么xpath解析出来的是空列表?from selenium import webdriver
from lxml import etree
import os
bro = webdriver.Chrome(executable_path="./chromedriver.exe")
if not os.path.exists("./wangyi list music"):
os.mkdir("./wangyi list music")
url = "https://music.163.com/m/playlist?id=6731975194"
bro.get(url)
page_text = bro.page_source
tree = etree.HTML(page_text)
tr_list = tree.xpath('//*[@id="auto-id-TEZk3fbkwpQOcPlD"]/table//tr')
for tr in tr_list:
try:
name = tr.xpath("./td[2]//span/a/b/@title")
id_ = tr.xpath("./td[2]//span/a/@href")
base_url = "http://music.163.com/song/media/outer/url?id=%s.mp3" % id_
content = req.get(url=base_url,headers=headers).content
with open("./wangyi list music/"+name+".mp3",'wb') as fp:
fp.write(content)
print(name+".mp3下载完成!")
except FileNotFoundError or OSError:
print(name+"因出错没有下载")
<iframe frameborder="0" id="auto-id-QVz7Ahov6EnUTTiV" style="display: none;" src="https://mail.163.com/app/cloudmusic/proxy.html" __idm_frm__="29"></iframe>
要先切进iframe里
|