Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How i can get all "div" elements from webpage?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.3k Views
  • 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 Offline
    Y Offline
    yoweb
    wrote on last edited by
    #1

    @ 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
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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
      0
      • K Offline
        K Offline
        KA51O
        wrote on last edited by
        #3

        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
        0
        • Y Offline
          Y Offline
          yoweb
          wrote on last edited by
          #4

          thank for all!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved