How do I read Text from HTML file ?
56 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Ned Gulley
2011 年 2 月 7 日
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.
2 件のコメント
Michael Lenihan
2011 年 12 月 1 日
Hi Ned, thats some useful code. Im trying to get a number from HTML code rather than txt. Any ideas?
Walter Roberson
2011 年 12 月 1 日
Same algorithm. You would use str2double() or sscanf() on the txt to convert to numeric form.
その他の回答 (2 件)
moahaimen talib
2017 年 10 月 28 日
hi i need to read just the email body how can i do that please
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!