0

I'm new at Python, and I'm trying to pull a list of artists and songs from Billboard's Hot 100 charts. I'm getting newline characters in my list of artists. How can I remove them without messing up the pairing and appearance of the list?

What I have:

from lxml import html
import requests

page = requests.get('https://www.billboard.com/charts/hot-100')
tree = html.fromstring(page.content)
songs = tree.xpath('//h2[@class="chart-row__song"]/text()')
artists = tree.xpath('//a[@class="chart-row__artist"]/text()')
pairedlist = [list(pair) for pair in zip(artists, songs)]   
for item in pairedlist:
    print (item)

What I get (sample):

['\nDrake\n', 'Nice For What']
['\nChildish Gambino\n', 'This Is America']
['\nDrake\n', "God's Plan"]
['\nElla Mai\n', 'Psycho']
['\nAriana Grande\n', 'The Middle']
['\nBTS\n', 'Yes Indeed']
['\nCamila Cabello\n', 'Meant To Be']
['\nEd Sheeran\n', "Boo'd Up"]
['\nCardi B\n', 'No Tears Left To Cry']
['\nImagine Dragons\n', 'Fake Love']
['\nShawn Mendes\n', 'Friends']
['\nKane Brown\n', 'Look Alive']
['\nRich The Kid\n', 'Never Be The Same']
['\nMaroon 5\n', 'Walk It Talk It']
['\nNicki Minaj\n', 'Perfect']
['\nPost Malone\n', 'Be Careful']
['\nThe Weeknd\n', 'Whatever It Takes']
user192085
  • 117
  • 1
  • 1
  • 11

1 Answers1

0

The python function strip will solve this for you. See this.