我会使用内置的QtWebKit。不知道在性能方面如何,但我认为应该抓住所有的“坏”HTML。
就像是:
class MyPageLoader : public QObject
{
Q_OBJECT
public:
MyPageLoader();
void loadPage(const QUrl&);
public slots:
void replyFinished(bool);
private:
QWebView* m_view;
};
MyPageLoader::MyPageLoader()
{
m_view = new QWebView();
connect(m_view, SIGNAL(loadFinished(bool)),
this, SLOT(replyFinished(bool)));
}
void MyPageLoader::loadPage(const QUrl& url)
{
m_view->load(url);
}
void MyPageLoader::replyFinished(bool ok)
{
QWebElementCollection elements = m_view->page()->mainFrame()->findAllElements("a");
foreach (QWebElement e, elements) {
// Process element e
}
}
使用该类
MyPageLoader loader;
loader.loadPage("http://www.example.com")
然后随着你喜欢的收藏。