How to parse HTML with C++/Qt?

NPLS picture NPLS · Sep 7, 2013 · Viewed 13.1k times · Source

How can i parse the following HTML

<body>
<span style="font-size:11px">12345</span>
<a>Hello<a>
</body>

I would like to retrive the data "12345" from a "span" with style="font-size:11px" from www.testtest.com, but I only want the that very data, and nothing else.

How can I accomplish this?

Answer

Lol4t0 picture Lol4t0 · Sep 7, 2013

I think QXmlQuery is what you want. I think the code will be like

QXmlQuery query;

query.setQuery(html, QUrl("/body/span[@style='font-size:11p']"));

QString r;
query.evaluateTo(&r);

You can also provide URL directly to the query

query.setQuery(QUrl("http://WWW.testtest.com"), QUrl("/body/span[@style='font-size:11p']"));