I would like to extract from a general HTML page, all the text (displayed or not).
I would like to remove
- any HTML tags
- Any javascript
- Any CSS styles
Is there a regular expression (one or more) that will achieve that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t really parse HTML with regular expressions. It’s too complex. RE’s won’t handle
<![CDATA[sections correctly at all. Further, some kinds of common HTML things like<text>will work in a browser as proper text, but might baffle a naive RE.You’ll be happier and more successful with a proper HTML parser. Python folks often use something Beautiful Soup to parse HTML and strip out tags and scripts.
Also, browsers, by design, tolerate malformed HTML. So you will often find yourself trying to parse HTML which is clearly improper, but happens to work okay in a browser.
You might be able to parse bad HTML with RE’s. All it requires is patience and hard work. But it’s often simpler to use someone else’s parser.