python 爬取周杰伦歌曲信息

#爬取的信息不在网页源代码里所以用json解析
import requests
# 引用requests库
res_music = requests.get('https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.song&searchid=60997426243444153&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=1&n=20&w=%E5%91%A8%E6%9D%B0%E4%BC%A6&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0')
# 调用get方法,下载这个字典
json_music = res_music.json()
# 使用json()方法,将response对象,转为列表/字典
list_music = json_music['data']['song']['list']
# 一层一层地取字典,获取歌单列表
for music in list_music:
    # list_music是一个列表,music是它里面的元素
    print(music['name'])
    # 以name为键,查找歌曲名
    print('所属专辑:'+music['album']['name'])
    # 查找专辑名
    print('播放时长:'+str(music['interval'])+'秒')
    # 查找播放时长
    print('播放链接:https://y.qq.com/n/yqq/song/'+music['mid']+'.html\n\n')
    # 查找播放链接

我来吐槽

*

*

已有 8 条评论

  1. Breanna Stretch

    Hello,

    It is with sad regret to inform you that DataList.biz is shutting down. We have made all our databases available for you at a one-time fee.

    You can visit us on DataList.biz

    Regards.
    Breanna

  2. Franchesca Robbins

    It is with sad regret to inform you that BusinessLeads101.com is shutting down.

    We have over 300 million records available for a one time fee of $149.

    Please visit our website BusinessLeads101.com

    Regards,
    Franchesca

  3. Alanna Beor

    Hello.

    We are offering Bullet Proof SMTP servers that never get suspended. Email as much as you want.

    DMCA ignored, bulletproof locations, 100% uptime guaranteed, unlimited data transfer, and 24/7/365 support.

    100 Spots available. BulletProofSMTP.org

  4. Constance Barff

    Hello.

    It is with sad regret to inform you TopDataList.com is shutting down.

    We have made all our databases available for you for a once off fee.

    Visit us on TopDataList.com

  5. Torsten Bond

    Hello, from CustomData.click we are a provider of unique databases that could help your business.

    Please visit us at CustomData.click to see if we can help you.

    Regards,
    Torsten

  6. Josephine De Gillern
    Josephine De Gillern May 18th, 2022 at 01:20 am 回复

    Hi, my name is Josephine from TopDataList.com

    We are ceasing operations on TopDataList.com and have made our leads available at a discounted price.

    Visit us on TopDataList.com
    Regards,
    Josephine

  7. Bruno Gresswell

    Hello, did you know that there are 241,120 internet directories in the world.

    These websites are what drive traffic to YOUR business.

    Want more traffic? Want more Sales? We can help - today.

    Your website wangwei520.top is listed in only 24 of these directories.

    Get more traffic for your Global audience.

    Our automated system adds your website to all of the directories.

    You can find it here: getlisted.directory/wangwei520.top

    Act today, and we will expedite your listings and waive the processing charge!

  8. Adam Murdock

    Convert wangwei520.top to an app with one click!

    80% of users browse websites from their phones.

    Have the App send out push notifications without any extra marketing costs!

    MakeMySiteMobile.com