def save_albums(self, artist_id): params = {'id': artist_id, 'limit': '200'} # 获取歌手个人主页 r = requests.get('http://music.163.com/artist/album', headers=self.headers, params=params) # 网页解析 soup = BeautifulSoup(r.content.decode(), 'html.parser') body = soup.body albums = body.find_all('a', attrs={'class': 'tit f-thide s-fc0'}) # 获取所有专辑 for album in albums: albume_id = album['href'].replace('/album?id=', '') sql.insert_album(albume_id, artist_id)
def save_albums(self, artist_id): params = {'id': artist_id, 'limit': '200'} # 获取歌手个人主页 r = requests.get('http://music.163.com/artist/album', headers=self.headers, params=params) # 网页解析 soup = BeautifulSoup(r.content.decode(), 'html.parser') body = soup.body #print(body) albums = body.find_all('a', href=re.compile(r'^/album\W\w*=[0-9]\d*')) # 获取所有专辑 for album in albums: album_id.add(album['href'][10:]) for albumid in album_id: sql.insert_album(albumid, artist_id)