使用 QtWebKit 显示,同时解析 xml

发布于 2024-08-31 19:10:59 字数 372 浏览 13 评论 0原文

我希望使用 QtWebKit 加载要显示的 url,但是,这是简单的部分,我可以做到这一点。我想做的是记录/记录 xml。我在这里的注意力是通过记录这些细节来即时记录和数据库化某些细节。

我的问题是,如何即时完成这一切,而不需要两次从服务器请求相同的 url,一次请求 xml,第二次请求查看 url。

我的希望是实现一种非常快速的方式来记录用户经过的设置数据。举个例子,我希望在用户查看网站时将这些详细信息存入数据库,而不是必须输入网站显示的详细信息。

现在,我正在使用 QtWebKit,并且我几乎已经解决了查看方面的所有问题。我有一个 loadUrl() 例程,它在 qwebview.h 中调用 load(url)

问题是,如何在此基础上进行 xml 解析?

I wish to use QtWebKit to load a url for display, but, that's the easy part, I can do that. What I wish to do is record / log xml as I go. My attention here is to record and database certain details on the fly, by recording those details.

My problem is, how to do this all on the fly, without requesting the same url from the server twice, once for the xml, and the second time to view the url.

My hope here, is to implement a very fast way of recording set data as the user passes over it. Take for example, rather then have to type out details displayed by a website, I wish to have those details chucked into a database as I the user views the website.

Now, I am using QtWebKit, and I have everything pretty much solved viewing wise. I have a loadUrl() routine which calls load(url) inside the qwebview.h

The problem is, how do I piggyback xml parsing on top of this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄居者 2024-09-07 19:10:59

在你的 loadUrl 中,使用 Qt 已经提供的 HTTP 下载工具(QNetworkRequest 和朋友)自行下载 url。

获得数据后,解析并记录它并使用:

void QWebView::setHtml ( const QString & html, const QUrl & baseUrl = QUrl() )

手动将其设置到 QWebView 中。第二个 url 参数是您拥有的 url,它将用作从页面引用的元素的基本 url。

如果您不确定是否下载了 html,请使用:

void QWebView::setContent ( const QByteArray & data, const QString & mimeType = QString(), const QUrl & baseUrl = QUrl() )

您也可以执行相反的操作。只需在方法中调用 QWebView::load(url) ,一旦传输完成,使用 QWebView::mainFrame() 获取主框架,然后使用 QWebFrame::toHtml() 获取内容,您可以解析并获取内容按照您的意愿登录。

In your loadUrl do the download of the url yourself using the HTTP download facilities Qt already provides (QNetworkRequest and friends).

Once you got the data, parse and log it and use:

void QWebView::setHtml ( const QString & html, const QUrl & baseUrl = QUrl() )

To set it into the QWebView manually. The second url parameter is the url you have, which will be used as a base url for the elements that are referenced from the page.

If you are not sure you downloaded html, then use:

void QWebView::setContent ( const QByteArray & data, const QString & mimeType = QString(), const QUrl & baseUrl = QUrl() )

You can also do the inverse. Just call QWebView::load(url) in your method, and once the transfer is complete, use QWebView::mainFrame() to get the main frame and then QWebFrame::toHtml() to get the content, which you can parse and log as you wish.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文