我正在使用QWebView加载为网站,然后从中抓取currentFrame()
。之后,我试图获得comment-text
类的div。这是我这样做的方式:
部分输入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>
以下是相关代码:
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'
答案 0 :(得分:2)
我正在使用QWebView加载为网站,然后我从中获取currentFrame()。之后,我尝试使用comment-text类来获得div。