More elegant way to create a list of lines from BeautifulSoup.findAll
I am writing a web parser using BeautifulSoup. I create a list of lines
generated with bs.findAll(text=True), and then split line for line and
apply my logic there. html_payload is an arbitrary webpage.
The code I've got so far works, but it's not very pretty, and makes me
think there must be a better, more elagant way of writing it.
data_to_parse = BeautifulSoup(html_payload)
lines_to_parse = []
d = data_to_parse.findAll(text=True)
for line in d:
for line2 in line.strip().split('\n'):
if line2:
lines_to_parse.append(line2)
for line in lines_to_parse:
pass # here's where I start analyzing results
Is there anyone who can suggest a better way of solving this?
No comments:
Post a Comment