How can I remove all the empty rows from my printed text using BS and Python? I'm still new, I think what I'm talking about maybe called whitespace?
Current output:
02:00 - 05:00 NHL: Columbus Blue Jackets at San Jose Sharks
- Channel 60
02:30 - 04:30 NCAAB: Quinnipiac vs Fairfield
- Channel 04
03:00 - 05:00 MLS: Portland Timbers at Los Angeles Galaxy
- Channel 05
Desired Output:
02:00 - 05:00 NHL: Columbus Blue Jackets at San Jose Sharks - Channel 60
02:30 - 04:30 NCAAB: Quinnipiac vs Fairfield - Channel 04
03:00 - 05:00 MLS: Portland Timbers at Los Angeles Galaxy - Channel 05
Code:
import urllib, urllib2, re, HTMLParser, os
from bs4 import BeautifulSoup
import os
pg_source = ''
req = urllib2.Request('http://rushmore.tv/schedule')
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36')
try:
response = urllib2.urlopen(req)
pg_source = response.read().decode('utf-8' , 'ignore')
response.close()
except:
pass
content = []
soup = BeautifulSoup(pg_source)
content = BeautifulSoup(soup.find('ul', { 'id' : 'myUL' }).prettify())
print (content.text)