当前位置:   article > 正文

基于python解析网易云歌单._歌单 解析

歌单 解析

在写到解析歌单的时候发现几个问题
获取歌曲名字和id的xpath写法明明和爬取热榜的写法一样解析歌单
热榜歌曲

id_list=html.xpath('//a[contains(@href,"song?")]')
id_list=id_list[0:-11]
for id in id_list:
    href=id.xpath('./@href')[0]
    song_id=href.split('=')[1]
    songid.append(song_id)
    song_name=id.xpath('./text()')[0]
    songname.append(song_name)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

但无法获取明文信息在这里插入图片描述
研究了下发现,歌单中的信息被放在了iframe里.
在这里插入图片描述

通过查询后发现可以通过安装selenium实现.如果仅仅作为爬虫工具来使用则很简单,没什么入门成本.

from selenium import webdriver
wd = webdriver.Chrome(r'd:\chromedriver.exe')
wd.get('https://music.163.com/#/playlist?id=6702371651')
wd.switch_to.frame(0)
elements =wd.find_elements_by_xpath('//a[contains(@href,"/song?id")]')
name=[]
for i in elements:
    print(i.get_attribute('href'))
elements2 =wd.find_elements_by_xpath('//b[@title]')
for i in elements2:
    print(i.get_attribute('title'))
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

获取成功
在这里插入图片描述
在这里插入图片描述

受限于未登录状态只能看到部分信息,只能看到十条

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/1015789
推荐阅读
相关标签
  

闽ICP备14008679号