Hi
I have downloaded page using urlopen. How do I remove all html tags from it? Is there any regexp to replace all <*> tags?
Hi
I have downloaded page using urlopen. How do I remove all html tags from it? Is there any regexp to replace all <*> tags?
A very simple regexp would be :
import re
notag = re.sub("<.*?>", " ", html)
The drawback of this solution is that it doesn't remove javascript or css, but only tags.
Try this:
import re
def remove_html_tags(data):
p = re.compile(r'<.*?>')
return p.sub('', data)
I can also recommend BeautifulSoup which is an easy to use html parser. There you would do something like:
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(html)
all_text = ''.join(soup.findAll(text=True))
This way you get all the text from a html document.