フィルターのクリア

How to access itemprop = "name" from within a data structure in HTML code using Matlab?

4 ビュー (過去 30 日間)
N/A
N/A 2019 年 3 月 26 日
コメント済み: Sean de Wolski 2019 年 3 月 29 日
HTML code
<div class="itemName largestFont" itemprop="name"> Information which I want to extract </div>
<div class="itemCategory largeFont"><a href="/somerandomwebsitelink"> Information which I dont need </a></div>
I want to extract the information from itemprop = "name" only
using the selector feature with text analytics,
I can do "selector = "DIV.itemHeader"
Item Header is the class in which both those div elements lie and as a result both of the information within those divs is extracted.
I only want the information from itemprop = "name"
How do I go about doing that?
  3 件のコメント
N/A
N/A 2019 年 3 月 26 日
Yup, thats correct
Walter Roberson
Walter Roberson 2019 年 3 月 26 日
Unfortunately I do not have that toolbox to test with.
My own implementation would probably be to use regexp with named tokens and the 'names' option.

サインインしてコメントする。

採用された回答

TADA
TADA 2019 年 3 月 26 日
編集済み: TADA 2019 年 3 月 27 日
I don't have the toolbox you mentioned, but it most likely uses xpath to parse the html...
I think the best options are xpath or regular expressions.
as far as I know to use xpath in matlab you have to use Java classes, but regular expressions are built in to matlab and they are very covenient.
The regex pattern could be something like that:
str = ['<div class="itemName largestFont" itemprop="name"> Information which I want to extract </div>'...
'<div class="itemCategory largeFont"><a href="/somerandomwebsitelink"> Information which I dont need </a></div>'];
match = regexp(str, '<div\s+(\w+="[^"]*"\s+)*itemprop="name"(\s+\w+="[^"]*")*\s*>(?<data>[^<]*)</div>', 'names')
match =
struct with fields:
data: ' Information which I want to extract '
  11 件のコメント
N/A
N/A 2019 年 3 月 28 日
HALLELUJAH! :D
TADA
TADA 2019 年 3 月 28 日
Cheers

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2019 年 3 月 28 日
編集済み: Sean de Wolski 2019 年 3 月 28 日
Using htmlTree, this is trivial:
tree = htmlTree(fileread('yourfile.html'))
div = tree.findElement('div')
item = div.getAttribute("itemprop")
names = item == "name"
div(names).extractHTMLText
  4 件のコメント
TADA
TADA 2019 年 3 月 28 日
Neither me nor Walter Robertson (as far as I know) work for mathworks... I'd gladly take that raise though :)
Sean de Wolski
Sean de Wolski 2019 年 3 月 29 日
@TADA, we're always hiring into MathWorks and have a distributor in Israel who may or may not be looking for MATLAB users.
@Shivam, this returns exactly what you want from your comment above:
s = string(webread("https://beta.trollandtoad.com/yugioh/invasion-of-chaos-ioc-unlimited-singles/manticore-of-darkness-ioc-067-ultra-rare-unlimited/1155511", weboptions('Timeout', 15)));
%%
tree = htmlTree(s)
%%
div = tree.findElement('div')
%%
item = div.getAttribute("itemprop")
%%
names = item == "name"
%%
div(names).extractHTMLText
ans =
"Manticore of Darkness - IOC-067 - Ultra Rare Unlimited"

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDiscrete Math についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by