extractHTMLText
HTML에서 텍스트 추출
구문
설명
예제
HTML에서 텍스트 추출하기
HTML 코드에서 텍스트 데이터를 바로 추출하려면 extractHTMLText
를 사용하고 HTML 코드를 string형으로 지정하십시오.
code = "<html><body><h1>THE SONNETS</h1><p>by William Shakespeare</p></body></html>";
str = extractHTMLText(code)
str = "THE SONNETS by William Shakespeare"
웹 사이트에서 텍스트 추출하기
웹 페이지에서 텍스트 데이터를 추출하려면 먼저 webread
함수를 사용하여 HTML 코드를 읽어오십시오. 그런 다음 반환된 코드에 extractHTMLText
함수를 사용합니다.
url = "https://www.mathworks.com/help/textanalytics";
code = webread(url);
str = extractHTMLText(code)
str = 'Text Analytics Toolbox Analyze and model text data Release Notes PDF Documentation Release Notes PDF Documentation Text Analytics Toolbox™ provides algorithms and visualizations for preprocessing, analyzing, and modeling text data. Models created with the toolbox can be used in applications such as sentiment analysis, predictive maintenance, and topic modeling. Text Analytics Toolbox includes tools for processing raw text from sources such as equipment logs, news feeds, surveys, operator reports, and social media. You can extract text from popular file formats, preprocess raw text, extract individual words, convert text into numerical representations, and build statistical models. Using machine learning techniques such as LSA, LDA, and word embeddings, you can find clusters and create features from high-dimensional text datasets. Features created with Text Analytics Toolbox can be combined with features from other data sources to build machine learning models that take advantage of textual, numeric, and other types of data. Get Started Learn the basics of Text Analytics Toolbox Text Data Preparation Import text data into MATLAB® and preprocess it for analysis Modeling and Prediction Develop predictive models using topic models and word embeddings Display and Presentation Visualize text data and models using word clouds and text scatter plots Language Support Information on language support in Text Analytics Toolbox'
HTML 트리에서 요소 찾기
webread
함수를 사용하여 URL https://www.mathworks.com/help/textanalytics
에서 HTML 코드를 읽어옵니다.
url = "https://www.mathworks.com/help/textanalytics";
code = webread(url);
htmlTree
를 사용하여 HTML 코드를 구문 분석합니다.
tree = htmlTree(code);
findElement
를 사용하여 HTML 트리에서 하이퍼링크를 모두 찾습니다. 하이퍼링크는 요소 이름이 "A"
인 노드입니다.
selector = "A";
subtrees = findElement(tree,selector);
처음 몇 개의 하위 트리를 표시합니다.
subtrees(1:10)
ans = 10×1 htmlTree: <A class="skip_link sr-only" href="#content_container">Skip to content</A> <A href="https://www.mathworks.com?s_tid=gn_logo" class="svg_link navbar-brand"><IMG src="/images/responsive/global/pic-header-mathworks-logo.svg" class="mw_logo" alt="MathWorks"/></A> <A href="https://www.mathworks.com/products.html?s_tid=gn_ps">Products</A> <A href="https://www.mathworks.com/solutions.html?s_tid=gn_sol">Solutions</A> <A href="https://www.mathworks.com/academia.html?s_tid=gn_acad">Academia</A> <A href="https://www.mathworks.com/support.html?s_tid=gn_supp">Support</A> <A href="https://www.mathworks.com/matlabcentral/?s_tid=gn_mlc">Community</A> <A href="https://www.mathworks.com/company/events.html?s_tid=gn_ev">Events</A> <A href="https://www.mathworks.com/products/get-matlab.html?s_tid=gn_getml">Get MATLAB</A> <A href="https://www.mathworks.com?s_tid=gn_logo" class="svg_link pull-left"><IMG src="/images/responsive/global/pic-header-mathworks-logo.svg" class="mw_logo" alt="MathWorks"/></A>
extractHTMLText
를 사용하여 하위 트리에서 텍스트를 추출합니다. 추출한 결과에 해당 페이지에 있는 각 링크의 링크 텍스트가 들어 있습니다.
str = extractHTMLText(subtrees); str(1:10)
ans = 10×1 string
"Skip to content"
""
"Products"
"Solutions"
"Academia"
"Support"
"Community"
"Events"
"Get MATLAB"
""
입력 인수
code
— HTML 코드
string형 배열 | 문자형 벡터 | 문자형 벡터로 구성된 셀형 배열
HTML 코드로, string형 배열, 문자형 벡터 또는 문자형 벡터로 구성된 셀형 배열로 지정됩니다.
팁
웹 페이지에서 HTML 코드를 읽어오려면
webread
를 사용하십시오.HTML 파일에서 텍스트를 추출하려면
extractFileText
를 사용하십시오.
예: "<a href='https://www.mathworks.com'>MathWorks</a>"
데이터형: char
| string
| cell
tree
— HTML 트리
htmlTree
배열
HTML 트리로, htmlTree
배열로 지정됩니다.
ex
— 추출 방법
'tree'
(디폴트 값) | 'article'
| 'all-text'
추출 방법으로, 다음 중 하나로 지정됩니다.
옵션 | 설명 |
---|---|
'tree' | DOM 트리와 텍스트 내용을 분석한 후 단락 블록을 추출합니다. |
'article' | 기사 텍스트를 검출하고 단락 블록을 추출합니다. |
'all-text' | 스크립트와 CSS 스타일을 제외하고, HTML 본문의 모든 텍스트를 추출합니다. |
버전 내역
R2018a에 개발됨
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)