Question: Using Beautiful Soup (bs4) create a python webscraper script that gets the following information from Billboard Top Hip-Hop Songs/R&B Songs Charts and exports the data

Using Beautiful Soup (bs4) create a python webscraper script that gets the following information from Billboard Top Hip-Hop Songs/R&B Songs Charts and exports the data to a .csv file.

Billboard Number, Artist Name, Song Title, Weeks On Chart, Peak Position, Latest Week Number, Last Week Peak and Top Songs Today In History. Top Songs Today In History should be populated with top 5 songs on this this day in the in the last 5 years.

This is the code that I currently have:

from urllib.request import urlopen as uReq from bs4 import BeautifulSoup as soup

my_url = 'https://www.billboard.com/charts/r-b-hip-hop-songs'

# Opens web connetion and grabs page uClient = uReq(my_url) page_html = uClient.read() uClient.close()

# HTML parsing page_soup = soup(page_html, "html.parser")

# Grabs song title, artist and picture containers = page_soup.findAll("div", {"class":"chart-row__main-display"})

# CSV filename creation filename = "Billboard_Hip_Hop_Charts.csv" f = open(filename, "w")

# Creating Headers headers = "Billboard Number, Artist Name, Song Title " f.write(headers)

# Get Billboard Number, Artist Name and Song Title for container in containers: # Gets billboard number billboard_number = container.div.span.text

# Gets artist name artist_name_a_tag = container.findAll("", {"class":"chart-row__artist"}) artist_name = artist_name_a_tag[0].text.strip()

# Gets song title song_title = container.h2.text

print("Billboard Number: " + billboard_number) print("Artist Name: " + artist_name) print("Song Title: " + song_title)

f.write(billboard_number + "," + artist_name.replace(",", "|") + "," + song_title + " ")

f.close()

This is what my .csv file looks like:

Using Beautiful Soup (bs4) create a python webscraper script that gets the

I'm using Python 3.6.4.

VfBillboard Number 1 Billboard Number Artist Name Song Title Nice For What Psycho God's Plan Better Now Rockstar Look Alive Paranoid Freaky Friday Rich & Sad Spoil My Night Ball For Me Walk It Talk It Same Bitches Like It Zack And Codeine Over Now Be Careful Takin' Shots Pray For Me Plug Walk Call Out My Name Finesse Candy Paint Boo'd Up Powerglide 92 Explorer ATM KOD Otherside Blame It On Me Kevin's Heart All The Stars Chun-Li Esskeetit Stir Fry Japan Sugar Wraith Drip Sad! King's Dead New Freezer Everyday 1 Drake 2 Post Malone Featuring Ty Dolla ?ign 3 Drake 4 Post Malone 5 Post Malone Featuring 21 Savage 6 BlocBoy JB Featuring Drake 7 Post Malone 8 Lil Dicky Featuring Chris Brown 10 9 Post Malone 10 Post Malone Featuring Swae Lee 11 Post Malone Featuring Nicki Minaj 12 Migos Featuring Drake 13 Post Malone Featuring G-Eazy & YG 14 Cardi Bl Bad Bunny & J Balvin 15 Post Malone 16 Post Malone 17 Cardi B 18 Post Malone 19 The Weeknd& Kendrick Lamar 20 Rich The Kid 21 The Weeknd 22 Bruno Mars & Cardi B 23 Post Malone 24 Ella Mai 25 Rae Sremmurd & Juicy J 26 Post Malone 27 J. Cole 28 J. Cole 29 Post Malone 30 Post Malone 31 J. Cole 32 Kendrick Lamar & SZA 33 Nicki Minaj 34 Lil Pump 35 Migos 36 Famous Dex 37 Post Malone 38 Cardi B Featuring Migos 39 XXXTENTACION 40 Jay Rock] Kendrick Lamarl Future & James Blake 41 Rich The Kid Featuring Kendrick Lamar 42 Logic & Marshmello 12 14 19 20 28 29 30 32 34 36 38 39 43 VfBillboard Number 1 Billboard Number Artist Name Song Title Nice For What Psycho God's Plan Better Now Rockstar Look Alive Paranoid Freaky Friday Rich & Sad Spoil My Night Ball For Me Walk It Talk It Same Bitches Like It Zack And Codeine Over Now Be Careful Takin' Shots Pray For Me Plug Walk Call Out My Name Finesse Candy Paint Boo'd Up Powerglide 92 Explorer ATM KOD Otherside Blame It On Me Kevin's Heart All The Stars Chun-Li Esskeetit Stir Fry Japan Sugar Wraith Drip Sad! King's Dead New Freezer Everyday 1 Drake 2 Post Malone Featuring Ty Dolla ?ign 3 Drake 4 Post Malone 5 Post Malone Featuring 21 Savage 6 BlocBoy JB Featuring Drake 7 Post Malone 8 Lil Dicky Featuring Chris Brown 10 9 Post Malone 10 Post Malone Featuring Swae Lee 11 Post Malone Featuring Nicki Minaj 12 Migos Featuring Drake 13 Post Malone Featuring G-Eazy & YG 14 Cardi Bl Bad Bunny & J Balvin 15 Post Malone 16 Post Malone 17 Cardi B 18 Post Malone 19 The Weeknd& Kendrick Lamar 20 Rich The Kid 21 The Weeknd 22 Bruno Mars & Cardi B 23 Post Malone 24 Ella Mai 25 Rae Sremmurd & Juicy J 26 Post Malone 27 J. Cole 28 J. Cole 29 Post Malone 30 Post Malone 31 J. Cole 32 Kendrick Lamar & SZA 33 Nicki Minaj 34 Lil Pump 35 Migos 36 Famous Dex 37 Post Malone 38 Cardi B Featuring Migos 39 XXXTENTACION 40 Jay Rock] Kendrick Lamarl Future & James Blake 41 Rich The Kid Featuring Kendrick Lamar 42 Logic & Marshmello 12 14 19 20 28 29 30 32 34 36 38 39 43

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!