How do I read Text from HTML file ?
125 views (last 30 days)
I would like to know how is it possible to read only text from HTML file. I assume matlab reads the source code of the file due to which along with the actual text, it also reads the tags and other script related data. Please let me know how can this be solved.
Ned Gulley on 7 Feb 2011
Try something like this:
url = 'http://www.example.com/';
html = urlread(url);
% Use regular expressions to remove undesired markup.
txt = regexprep(html,'<script.*?/script>','');
txt = regexprep(txt,'<style.*?/style>','');
txt = regexprep(txt,'<.*?>','')
Once you have all the HTML, you can sift out the style and script blocks. Then remove any remaining tags and the result is reasonably clean. It won't be perfect, but it's easy to tune from here.