Python爬虫实战(1)之千千音乐热歌前50
2019-03-20 20:21
183 查看
爬取内容目标
分析
1.歌曲名称(在class=“song-title”的span下的a标签内)
2.获取作者(class=“author_list” 的span 的title属性)
代码
import requests from bs4 import BeautifulSoup ''' 1.目标网址 :http://music.taihe.com/top/dayhot 2.发送请求,获得响应 3.获取BeautifulSoup对象 ''' url="http://music.taihe.com/top/dayhot" header={ "Accept-Language":"zh-CN,zh;q=0.8", "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.108 Safari/537.36 2345Explorer/8.1.0.14126" } html=requests.get(url,headers=header) soup=BeautifulSoup(html.content,'lxml') ####获取歌名 alltitle=soup.select("span.song-title"); titlelist=[] #存放歌名 for t in alltitle: titlelist.append(t.a.text) print(len(titlelist)) ##100首歌这里 虽然一个页面显示50 其实他是将另外50个隐藏 ##获取歌手名 allsinger=soup.select("span.author_list") singerlist=[] for t in allsinger: singerlist.append(t.get("title")) print(len(singerlist)) ####结果输出 for i in range(0,len(singerlist)): print(titlelist[i]+'-------'+singerlist[i])
结果
相关文章推荐
- Python爬虫实战之豆瓣音乐、微打赏、阳光电影(附代码)
- python爬虫实战 - 糗事百科数据的爬取
- python3爬虫 - cookie登录实战
- 10Python爬虫---爬虫实战之糗事百科段子
- Python3实战之爬虫抓取网易云音乐的热门评论
- python3 [入门基础实战] 爬虫入门之爬取豆瓣阅读中文电子书[热门排序]
- Python爬虫实战案例:爬取爱奇艺VIP视频
- Python网络爬虫实战案例之:7000本电子书下载(2)
- Python爬虫实战一:爬取糗事百科的文本段子
- python网络爬虫实战--重点整理
- python 爬虫实战(二)使用pyspider爬取菜谱及图片
- Python爬虫框架Scrapy实战之批量抓取招聘信息
- 《Python 3网络爬虫开发实战》附源码
- python爬虫实战——5分钟做个图片自动下载器
- Python爬虫开发与项目实战 1:回顾Python编程
- [python爬虫]--爬取豆瓣音乐topX
- Python爬虫实战(3):安居客房产经纪人信息采集
- Python爬虫实战:糗事百科
- python爬虫实战-爬附近肯德基信息(ajax-post)