I'm new to web scraping and I'm trying to scrape the Billboard Global 200 and I just cant get the Weeks on Chart.
For Example, SZA has Kill Bill for 4 weeks on chart and so on. I cant figure out what to put on the WeeksOnChart variable to get that number 4
source = requests.get('https://www.billboard.com/charts/billboard-global-200/')
source.raise_for_status()
soup = BeautifulSoup(source.text, 'html.parser')
music = soup.find_all('div', class_='o-chart-results-list-row-container')
for songs in music:
songTitle = songs.find('h3').text.strip()
songArtist = songs.find('h3').find_next('span').text.strip()
songRank = songs.find('span').text.strip()
WeeksOnChart = songs.find(???)
Please help thanks.
CodePudding user response:
I wouldn't normally recommend this because it's very prone to errors but I couldn't find a good unique identifier for that element. You can do this to narrow down by choosing the first "li" element with that class and then find the "ul" containing your element etc... Here is the code I used to get it:
songs.find_all("li",class_="lrv-u-width-100p")[0].find_all("ul")
[0].find_all("li")[5].text.strip()