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 スカラー、文字ベクトル、または文字ベクトルを含むスカラー cell 配列として指定します。
出力引数
HTML 属性。string 配列として返されます。
詳細
一般的な HTML 要素には、次のコンポーネントが含まれます。
要素名 – HTML タグの名前。要素名は、HTML ツリーの
Name
プロパティに対応します。属性 – タグに関する追加情報。HTML 属性の形式は
で、name
="value
"
とname
はそれぞれ属性名と値を示します。属性は HTML の開始タグの内部に出現します。HTML ツリーから属性値を取得するには、value
getAttribute
を使用します。コンテンツ – 要素のコンテンツ。コンテンツは 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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)