Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Accessing text between two QWebElement objects in DOM
Forum Updated to NodeBB v4.3 + New Features

Accessing text between two QWebElement objects in DOM

Scheduled Pinned Locked Moved Qt WebKit
2 Posts 2 Posters 958 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    silicomancer
    wrote on last edited by
    #1

    I am traversing a DOM using Qt's WebKit classes. Please have a look on the following pseudo HTML:

    @<br>111<a class="node">AAA</a>
    <br>222<a class="node">BBB</a>
    ...@

    I can easily find the anchors using findAll(). However I also need to get the text before the elements ("111" and "222"). I tried to use previousSibling() but of course that gives me the <br> element since the "111" and "222" texts are no elements.

    I found a function to access text within an element, but how can I access between the <br> and the <a> elements?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      brugge
      wrote on last edited by
      #2

      You can use JavaScript. First find anchors, and then:
      @QString textBeforeAnchor = anchorElement.evaluateJavaScript("this.previousSibling.textContent").toString();@

      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