爬取网易云音乐
为什么我的xpath解析出来的是空列表啊?{:10_277:}from selenium import webdriver
from lxml import etree
import os
bro = webdriver.Chrome(executable_path="./chromedriver.exe")
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')
if not os.path.exists("./wangyi list music"):
os.mkdir("./wangyi list music")
try:
for id_ in id_list:
id_ = id_.split('=')[-1]
name = name_list
i +=1
base_url = "http://music.163.com/song/media/outer/url?id=%s.mp3" % id_
content = req.get(url=base_url+id_,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+"因出错没有下载")
错了错了 代码粘错了{:10_284:} 无枝为檄 发表于 2021-6-19 10:53
错了错了 代码粘错了
有些时候光用xpath或者css定位不准确,
推荐用css-selector定位大体为止再用re精确定位。
页:
[1]