標籤:
1.下載Htmlcxx,http://sourceforge.net/projects/htmlcxx/
2.解壓htmlcxx-0.85.tar.gz
3.開啟htmlcxx.vcproj,注意是htmlcxx.vcproj,不是下面的htmlcxxapp.vcproj
4.使用VS開啟htmlcxx.vcproj,需要對項目進行轉換
5.選擇編譯模式:Debug或Release模式,具體由需要使用到Htmlcxx庫檔案的項目的編譯模式決定,但注意Debug對Debug,Release對Release,不要混亂
6.右擊htmlcxx,選擇屬性,可以看到運行庫預設的是”多線程調試/MTD“:
7.具體選擇運行庫時,由由需要使用到Htmlcxx庫檔案的項目的運行庫決定,由於本人項目使用的是”多線程調試 DLL (/MDd)“,故選擇”多線程調試 DLL (/MDd)“進行編譯
8.報錯:
9.排錯:
改成
10.在所開發專案檔夾中,建立”htmlcxx“檔案,裡面添加兩個子檔案夾”lib“和”include“
11.將編譯好的htmlcxx.lib(Debug或者Release,由htmlcxx編譯模式決定)拷貝到lib檔案夾,將html檔案夾中所有的.h標頭檔和ParserSax.tcc添加到include檔案夾
12.選擇所開發項目的項目屬性,添加庫檔案htmlcxx.lib到項目中(VC++目錄下的庫目錄中添加htmlcxx.lib路徑即可)
13.所開發的項目的標頭檔中添加以下內容:
#include <string>#include "htmlcxx/include/ParserDom.h"using namespace std;using namespace htmlcxx;#pragma comment(lib,"htmlcxx.lib")
14.具體使用代碼:
void NuistMoney::GetLogWeekTxt(){if (logined==true){logWidget->clear();lbmessage->setText(tr("正在查詢本周消費,請稍候..."));QString data=GetToAllNet(tr("http://www.**************.com.cn"));string html=data.toStdString();HTML::ParserDom parser;tree<HTML::Node> dom = parser.parseTree(html);tree<HTML::Node>::iterator it ;tree<HTML::Node>::iterator end;//輸出所有的文本節點it= dom.begin();end= dom.end();QString str;QString str1;QString str2;for(; it != end; ++it){if (strcasecmp(it->tagName().c_str(), "td") == 0)//首先判斷是否是td欄位{it+=1;//如果是td欄位,則讀取下一個欄位的值,<td>欄位1</td><td>欄位2</td>,擷取欄位2if ((!it->isTag()) && (!it->isComment())){if (it->text()!=" "){str1=QString::fromStdString(it->text()).trimmed();}}if (str1==tr("交易金額")||str1==tr("卡餘額")){it+=5;}else{it+=3;}str2=QString::fromStdString(it->text()).trimmed();str=tr("\t")+str1+tr("\t\t")+str2;logWidget->addItem(str);}if (str1==tr("卡餘額")){logWidget->addItem(tr(" "));str1.clear();}}}else{lbmessage->setText(tr("您未登陸,請您先登陸..."));}}
附上htmlcxx學習資料:http://blog.csdn.net/youfangyuan/article/details/7816518
C++ 使用Htmlcxx解析Html內容(VS編譯庫檔案)