Reputation: 93
what library do I have to use to get data from website.
For example I have such a case:
<html>
<body>
<div class = "MyClass">
<div class = "MyClass2"> </div>
</div>
</body>
</html>
And how do I get the name of the second class(Myclass2
), what method do I have to use?
I just wanna mention that in c# it was very easy here is more complicated in my opinion.
I was using QWebElement
class but I haven't found proper method.
Greetings
Upvotes: 2
Views: 1865
Reputation: 32635
You can use QWebPage
class which provides an object to view and edit web documents. Using QWebElement
you can access to DOM elements in a QWebFrame
:
QWebPage page;
page.mainFrame()->load(url);
QWebFrame * frame = page.mainFrame();
QWebElement doc = frame->documentElement();
QWebElement body = doc.firstChild();
QWebElement first = body.firstChild();
QWebElement second = body.firstChild();
QString str = second.attribute("class");
Upvotes: 1
Reputation: 563
You can use QXmlStreamReader to access your Dokument too.
Example loop:
QXmlStreamReader xml;
...
while (!xml.atEnd()) {
xml.readNext();
... // do processing
}
if (xml.hasError()) {
... // do error handling
}
A helpful Example: QXmlStream Bookmarks Example
Upvotes: 0