Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    How i can get all "div" elements from webpage?

    General and Desktop
    3
    4
    2152
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      yoweb last edited by

      @ ui->webView->load(QUrl("http://stackoverflow.com"));
      ..................................
      QWebElementCollection collection = frame->findAllElements("div");
      foreach (QWebElement element, collection)
      {
      qDebug() << element.attribute("id");
      }@
      How i can get all "div" elements from webpage?

      I want get result:
      div id = test1
      div id = test2

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        QWebView::Load() operates asynchronously, thus you have to wait until the page is fully loaded before you can get all the elements.
        Do this by listen to the "QWebView::loadFinished()":http://qt-project.org/doc/qt-4.8/qwebview.html#loadFinished signal.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • K
          KA51O last edited by

          I used "QWebFrame::findAllElements()":http://qt-project.org/doc/qt-4.8/qwebframe.html#findAllElements succesfully for this. Of course as raven-worx pointed out the page must first finish loading.

          @
          QWebElementCollection result = yourWebView->page()->mainFrame()->findAllElements("div");
          @

          1 Reply Last reply Reply Quote 0
          • Y
            yoweb last edited by

            thank for all!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post