How to access itemprop = "name" from within a data structure in HTML code using Matlab?
Ältere Kommentare anzeigen
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 Kommentare
Walter Roberson
am 26 Mär. 2019
Are you using the Text Analytics Toolbox? https://www.mathworks.com/help/textanalytics/ug/parse-html-and-extract-text-content.html
N/A
am 26 Mär. 2019
Walter Roberson
am 26 Mär. 2019
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.
Akzeptierte Antwort
Weitere Antworten (1)
Sean de Wolski
am 28 Mär. 2019
Bearbeitet: Sean de Wolski
am 28 Mär. 2019
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 Kommentare
N/A
am 28 Mär. 2019
TADA
am 28 Mär. 2019
Neither me nor Walter Robertson (as far as I know) work for mathworks... I'd gladly take that raise though :)
Sean de Wolski
am 29 Mär. 2019
@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"
Kategorien
Mehr zu Language Support finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!