import requests
from lxml import etree
url = "https://music.163.com/discover/toplist?id=19723756"
headers = {
'User-Agent': "PostmanRuntime/7.15.2",
}
response = requests.request("GET", url, headers=headers)
'''
”<”、”&”
'''
r = etree.HTML(response.text)
l = r.xpath("//textarea[@id='song-list-pre-data']/text()")
print(l)
最终输出(支只复制了最后一段):
lLevel":"exhigh","pl":320000},"djid":0,"fee":0,"album":{"id":158052587,"name":"Sakana~( ˵>ㅿㅿ\n']
正常来说 这个xpath语句 是匹配到一个完整的json形式数据 但是遇到了特殊符号 就在特殊符号处匹配结束了 导致信息拿不全
求教大神如何处理