이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.
getAttribute
설명
예제
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"
입력 인수
tree
— HTML 트리
htmlTree
배열
HTML 트리로, htmlTree
배열로 지정됩니다.
attr
— 특성 이름
string형 스칼라 | 문자형 벡터 | 문자형 벡터를 포함하는 스칼라 셀형 배열
특성 이름으로, string형 스칼라, 문자형 벡터 또는 문자형 벡터를 포함하는 스칼라 셀형 배열로 지정됩니다.
출력 인수
str
— HTML 특성
string형 배열
HTML 특성으로, string형 배열로 반환됩니다.
세부 정보
HTML 요소
일반적인 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 명령
다음 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)