Search code examples
htmlc++cssqtqwebview

Not getting desired output from QWebFrame's findAllElements();


I am using a QWebView to load as website, then I grab the currentFrame() from it. After that I attempt to get a div with the class of comment-text. Here is the way I did this: Partial Input HTML:

<div class="content">
   <span class="byline">
   <span class="author">
   <span aria-label="Verified" class="yt-channel-title-icon-verified yt-uix-tooltip yt-sprite" data-tooltip-text="Verified"></span>
   <span class="badges">
   <span aria-label="Owner" class="yt-chat-badge badge-owner yt-uix-tooltip yt-sprite" data-tooltip-text="Owner"></span>
   <span aria-label="Moderator" class="yt-chat-badge badge-moderator yt-uix-tooltip yt-sprite" data-tooltip-text="Moderator"></span>
   <span aria-label="Sponsor" class="yt-chat-badge badge-member yt-uix-tooltip yt-sprite" data-tooltip-text="Sponsor"></span>
   </span>
   <a href="https://gaming.youtube.com/channel/UCY88BS-9dTTHl7As46eFyuw" class="yt-uix-sessionlink yt-user-name" data-sessionlink="ei=pUqQV8j6N4rWuQLQmZ3AAQ" data-ytid="UCY88BS-9dTTHl7As46eFyuw" dir="ltr" data-name="">Andres Casanovas</a>
   </span>
   </span>
   <div class="comment-text" dir="ltr">
      he needs thorn
   </div>
   <div class="deleted-message-text">
   </div>
   <div class="inline-error inline-message">
      Message not sent: <span class="inline-error-message"></span>
   </div>
   <div class="inline-moderator-message inline-message"></div>
</div>

And here's the relevant code:

    YouTubeWebview = new QWebView();
    QEventLoop YouTubePageLoop1;
    connect(YouTubeWebview, SIGNAL(loadFinished(bool)), &YouTubePageLoop1, SLOT(quit()));
    connect(YouTubeWebview, SIGNAL(loadFinished(bool)), this, SLOT(YouTubeWebview_finishedLoading(bool)));
    YouTubeWebview->load(QUrl("live_stream_url"));
    YouTubePageLoop1.exec();
    YouTubeWebview->show();
    QWebElementCollection elements = YouTubeWebview->page()->currentFrame()->findAllElements("div.comment-text");
    qDebug() << elements.count();//Outputs '0'

Solution

  • am using a QWebView to load as website, then I grab the currentFrame() from it. After that I attempt to get a div with the class of comment-text.