주요 콘텐츠

getAttribute

HTML 트리의 루트 노드의 HTML 특성 읽어오기

설명

str = getAttribute(tree,attr)tree의 루트 노드의 특성 attr을 반환합니다. 이 특성이 설정되어 있지 않으면 함수가 missing 값을 반환합니다.

예제

예제

모두 축소

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&amp;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형 배열로 반환됩니다.

세부 정보

모두 축소

버전 내역

R2018b에 개발됨