getAttribute
HTML 트리의 루트 노드의 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="svg_link navbar-brand" href="https://www.mathworks.com?s_tid=gn_logo"><IMG alt="MathWorks" class="mw_logo" src="/images/responsive/global/pic-header-mathworks-logo.svg"/></A> <A class="mwa-nav_login" href="https://www.mathworks.com/login?uri=http://www.mathworks.com/help/textanalytics/index.html">Sign In</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/company/aboutus/contact_us.html?s_tid=gn_cntus">Contact Us</A> <A href="https://www.mathworks.com/store?s_cid=store_top_nav&s_tid=gn_store">How to Buy</A>
getAttribute
를 사용하여 하이퍼링크 참조를 가져옵니다. 특성 이름 "href"
를 지정합니다.
attr = "href";
str = getAttribute(subtrees,attr);
str(1:10)
ans = 10×1 string array
"https://www.mathworks.com?s_tid=gn_logo"
"https://www.mathworks.com/login?uri=http://www.mathworks.com/help/textanalytics/index.html"
"https://www.mathworks.com/products.html?s_tid=gn_ps"
"https://www.mathworks.com/solutions.html?s_tid=gn_sol"
"https://www.mathworks.com/academia.html?s_tid=gn_acad"
"https://www.mathworks.com/support.html?s_tid=gn_supp"
"https://www.mathworks.com/matlabcentral/?s_tid=gn_mlc"
"https://www.mathworks.com/company/events.html?s_tid=gn_ev"
"https://www.mathworks.com/company/aboutus/contact_us.html?s_tid=gn_cntus"
"https://www.mathworks.com/store?s_cid=store_top_nav&s_tid=gn_store"
입력 인수
HTML 트리로, htmlTree
배열로 지정됩니다.
특성 이름으로, string형 스칼라, 문자형 벡터 또는 문자형 벡터를 포함하는 스칼라 셀형 배열로 지정됩니다.
출력 인수
HTML 특성으로, string형 배열로 반환됩니다.
세부 정보
일반적인 HTML 요소에는 다음과 같은 성분이 들어 있습니다.
요소 이름 – HTML 태그의 이름. 요소 이름은 HTML 트리의
Name
속성에 해당합니다.특성 – 태그에 대한 추가 정보. HTML 특성은
형식입니다. 여기서name
="value
"
과name
는 각각 특성 이름과 특성 값을 나타냅니다. 특성은 여는 HTML 태그 안에 있습니다. HTML 트리에서 특성 값을 가져오려면value
getAttribute
를 사용하십시오.내용 – 요소 내용. 내용은 여는 HTML 태그와 닫는 HTML 태그 사이에 있습니다. 내용은 텍스트 데이터이거나 중첩된 HTML 요소일 수 있습니다.
htmlTree
객체에서 텍스트를 추출하려면extractHTMLText
를 사용하십시오.htmlTree
객체의 중첩된 HTML 요소를 가져오려면Children
속성을 사용하십시오.
예를 들어 HTML 요소 <a href="https://www.mathworks.com">Home</a>
은 다음 성분으로 이루어져 있습니다.
성분 | 값 | 설명 | |
---|---|---|---|
요소 이름 | a | 하이퍼링크에 해당하는 요소 | |
특성 | 특성 이름 | href | 하이퍼링크 참조 |
특성 값 | "https://www.mathworks.com" | 하이퍼링크 참조 값 | |
내용 | Home | 표시할 텍스트 |
버전 내역
R2018b에 개발됨
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- 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)