爬取网易云音乐
为什么xpath解析出来的是空列表?{:10_277:} from selenium import webdriverfrom 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//span/a/b/@title")
id_ = tr.xpath("./td//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里 南归 发表于 2021-6-19 15:35
要先切进iframe里
切进iframe是这样吗:
bro.switch_to.frame('g_iframe') 'g_iframe' 可能要根据情况变化,分析网页吧 南归 发表于 2021-6-19 15:58
'g_iframe' 可能要根据情况变化,分析网页吧
终于可以了 谢谢{:10_254:}
页:
[1]