- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
from bs4 import BeautifulSoup
import requests
user = "**********"
r = requests.get('https://www.last.fm/user/' + user)
soup = BeautifulSoup(r.content, 'html.parser')
page = soup.prettify()
#Top artists
print(
page[int(page.find('’s top artists: ') + len('’s top artists: ')):int(page.find('. Get your own music profile at Last.fm')):]
)
#Top track
print(
''.join(i if i != "+" else " " for i in (page[int(page.find('data-analytics-action="FeaturedTrackTrackName" href="/music/') + len('data-analytics-action="FeaturedTrackTrackName" href="/music/')):int(page.find('/_/', int(page.find('data-analytics-action="FeaturedTrackTrackName" href="/music/') + len('data-analytics-action="FeaturedTrackTrackName" href="/music/')))):] + " - " + page[int(page.find('/_/')) + 3:page.find('"', int(page.find('/_/'))):]))
)