0

so i'm making alittle project as i am a beginner and i'm doing some webscraping. I wanted to print the lyrics of a song each on it's line using beautifulsoup in python but instead it's printing like this:

I looked out this morning and the sun was goneTurned on some music to start my dayI lost myself in a familiar songI closed my eyes and I slipped awayIt's more than a feeling (more than a feeling)When I hear that old song they used to play (more than a feeling)And I begin dreaming (more than a feeling)Till I see Marianne walk awayI see my Marianne walkin' awaySo many people have come and goneTheir faces fade as the years go byYet I still recall as I wander onAs clear as the sun in the summer skyIt's more than a feeling (more than a feeling)When I hear that old song they used to play (more than a feeling)And I begin dreaming (more than a feeling)Till I see Marianne walk awayI see my Marianne walkin' awayWhen I'm tired and thinking coldI hide in my music, forget the dayAnd dream of a girl I used to knowI closed my eyes and she slipped awayShe slipped awayIt's more than a feeling (more than a feeling)When I hear that old song they used to play (more than a feeling)And I begin dreaming (more than a feeling)Till I see Marianne walk away

This is my code:

import urllib
from bs4 import BeautifulSoup

html = urllib.urlopen("http://www.metrolyrics.com/more-than-a-feeling-lyrics-boston.html")

bsObj = BeautifulSoup(html, "lxml")

namelist = bsObj.find_all("div", {"id": "lyrics-body-text"})

print("".join([p.get_text(strip=True) for p in namelist]))

2 Answers 2

1

You need to remove the strip = True parameter to get_text. That strips the string resulting in the joined output you see.

By removing it:

print("".join([p.get_text() for p in namelist]))  

It prints fine.

Sign up to request clarification or add additional context in comments.

2 Comments

hello, i've tryed it before but it still prints like this
hello, strip False is doing the job :) so does your syntax, thanks alot :)
0

Try writing it into a simple for loop

for p in namelist:
    print(p.get_text(strip=True))

2 Comments

hello, it does the same :\
If you are using Python 3, try making the print statement into print(p.get_text(strip=True),end='\n'). Or try setting the strip parameter to False.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.