I am trying to write a function that I can reuse to strip whitespace from scraped elements. I am scraping h2
, li
and p
tags; they are currently being returned as <tag> string </tag>
and I'd like to remove the whitespace and save the content back using *.get_text(strip=True)
.
h_content = soup.select('h2')
will store all the h2
tags found.
p_content = soup.select('p')
will store all the p
tags found.
And so on.
I have been trying this but am not sure how to return the items to the original location, that is to say, return them here --> *_content
def remove_whitespace(tags):
for item in tags:
item.get_text(strip=True)
return item
The ideal situation is to end up with a function that I can reuse.
remove_whitespace(*_content)