piess105
piess105

Reputation: 93

Qt read data from website

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

Answers (2)

Nejat
Nejat

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

Matthias
Matthias

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

Related Questions