Crossin的编程教室

标题: 爬虫求助?哪里有问题啊 [打印本页]

作者: 鹤鹤哒    时间: 2018-6-11 00:12
标题: 爬虫求助?哪里有问题啊
import requests
import json
import re
from bs4 import BeautifulSoup

def get_music_ids_by_musican_id(singer_id):
    singer_url = 'https://y.qq.com/n/yqq/singer/004WgCsE3KBddt.html#stat=y_new.singerlist.singername'
    r = requests.get(singer_url)
    soupObj = BeautifulSoup(r.text,'lxml')
    song_ids=soupObj.find('textarea').text
    jobj = json.loads(song_ids)
    for item in jobj:
       return(item['id'])

def get_lrc(music_id):
    url = 'https://y.qq.com/n/yqq/song/'+ str(music_id)
    r = requests.get(url)
    json_obj = r
    j = json.loads(json_obj)
    lrc = j['lrc']['lyric']
    pat = re.compile(r'\[.*\]')
    lrc = re.sub(pat,"",lrc)  
    lrc = lrc.strip()
    return lrc         

if __name__=="__main__":
     music_id=get_music_ids_by_musican_id(1)
     lrc=get_lrc(music_id)
     fp=open('歌词.txt',mode='w')
     fp.write(lrc)


作者: yiniuyun0    时间: 2019-6-21 15:33
看不懂哎




欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/) Powered by Discuz! X2.5