string
구문 분석된 HTML 트리를 string형으로 변환하기
설명
는 str
= string(tree
)htmlTree
객체 tree
를 string형으로 변환합니다.
팁
string
함수를 사용하여 htmlTree
객체의 기본 HTML 코드를 검사할 수 있습니다. htmlTree
객체의 요소를 탐색하려면 findElement
함수를 사용합니다.
예제
구문 분석된 HTML 코드를 string형으로 변환하기
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 트리에서 단락을 모두 찾습니다. 단락은 요소 이름이 "P"인 노드입니다.
subtrees = findElement(tree,"P");
string
함수를 사용하여 하위 트리를 string형으로 변환합니다.
str = string(subtrees)
str = 26×1 string
"<P class="h1">↵ <A href="../index.html" class="coming_from_product">Documentation</A>↵ <A href="../index.html" class="not_coming_from_product">Help Center</A>↵</P>"
"<P>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.</P>"
"<P>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.</P>"
"<P>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.</P>"
"<P class="category_desc">Learn the basics of Text Analytics Toolbox</P>"
"<P class="category_desc">Import text data into MATLAB<SUP>®</SUP> and preprocess it for analysis</P>"
"<P class="category_desc">Develop predictive models using topic models and word embeddings</P>"
"<P class="category_desc">Visualize text data and models using word clouds and text scatter plots</P>"
"<P class="category_desc">Information on language support in Text Analytics Toolbox</P>"
"<P>You clicked a link that corresponds to this MATLAB command:</P>"
"<P>Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.</P>"
"<P>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: <STRONG class="recommended-country"/>.</P>"
"<P>You can also select a web site from the following list:</P>"
"<P>Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.</P>"
"<P class="text-center">↵ <A href="#" class="worldwide_link">Contact your local office</A>↵</P>"
"<P class="ff_section_title">Explore Products</P>"
"<P class="ff_section_title">Try or Buy</P>"
"<P class="ff_section_title">Learn to Use</P>"
"<P class="ff_section_title">Get Support</P>"
"<P class="ff_section_title">About <SPAN translate="no">MathWorks</SPAN></P>"
"<P class="h4 add_font_futura_medium add_margin_0">↵ <SPAN translate="no">MathWorks</SPAN>↵</P>"
"<P>↵ <EM>Accelerating the pace of engineering and science</EM>↵</P>"
"<P><SPAN translate="no">MathWorks</SPAN> is the leading developer of mathematical computing software for engineers and scientists.</P>"
"<P>↵ <A href="/discovery.html?s_tid=all_disc_mw_ff">Discover...</A>↵</P>"
"<P class="copyright" translate="no">© 1994-2021 The MathWorks, Inc.</P>"
"<P>↵ <EM>Join the conversation</EM>↵</P>"
입력 인수
tree
— HTML 트리
htmlTree
배열
HTML 트리로, htmlTree
배열로 지정됩니다.
버전 내역
R2018b에 개발됨R2021a: htmlTree
객체에 string
함수를 사용하면 2칸 공백 들여쓰기가 적용됨
htmlTree
객체에 대한 string
함수의 출력값은 가독성을 위해 자동으로 들여씁니다. R2021a부터 이 함수는 두 개의 공백 문자를 사용하여 HTML 코드를 들여씁니다. 이전 릴리스에서는 이 함수가 네 개의 공백 문자를 사용하여 HTML 코드를 들여씁니다.
이 변경 사항은 HTML 문자열을 직접 구문 분석하는 코드에 영향을 미칩니다. HTML 코드를 구문 분석하고 탐색하려면 htmlTree
객체를 사용합니다.
R2021a: htmlTree
객체에 대한 string
함수는 특성을 다른 순서로 반환함
htmlTree
객체를 만드는 경우 입력 HTML 코드의 HTML 요소 특성을 자동으로 구문 분석합니다. R2021a부터는 HTML 요소 특성을 구문 분석하는 데 업데이트된 알고리즘을 사용합니다. 이 변경 사항으로 인해 string
함수가 HTML 코드를 반환할 때 특성을 다른 순서로 반환할 수 있습니다.
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)