Search code examples
pythonjoinstrip

Using the Join command to eliminate extra paragraph breaks


So I have this text:

 '
 Location
 Address

 Number

 Website
'

Except the top and bottom lines are empty as well, there aren't single quotes on those two lines. I basically want to make sure each line is one after another without any line breaks. This is what I would like it to look like.

 Location
 Address
 Number
 Website

I want to strip all of the line breaks and just have each result one line after another. This is the code to scrape the information from a webpage.

results = soup.findAll('div', class_='name')
for each in results:
    worksheet.write(row,1,each.text)
    row += 1

Each time I run through this, I want the results to print one line after another. Thanks.


Solution

  • Is there a reason you cannot use a simple if?

    results = soup.findAll('div', class_='name')
    for each in results:
        if each.text:
            worksheet.write(row,1,each.text)
            row += 1