How do I read Text from HTML file ?

조회 수: 65 (최근 30일)
vish
vish 2011년 2월 7일
답변: moahaimen talib 2017년 10월 28일
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
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
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
Walter Roberson 2011년 12월 1일
Same algorithm. You would use str2double() or sscanf() on the txt to convert to numeric form.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Kaustubha Govind
Kaustubha Govind 2011년 2월 7일
if the HTML file consists of valid XML, you might be able to use xmlread.

moahaimen talib
moahaimen talib 2017년 10월 28일
hi i need to read just the email body how can i do that please

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by