c++如何读取HTML文件源代码

2025-04-13 06:15:13
推荐回答(2个)
回答1:

这要用到MFC类库
1.添加头文件 #include

2.添加代码
CString strAddress="http://www.baidu.com";
CInternetSession mySession(NULL,0);
CHttpFile* myHttpFile=NULL;
CString strsource,strline;
myHttpFile=(CHttpFile*)mySession.OpenURL(strAddress);
while(myHttpFile->ReadString(strline))
{
strsource+=strline;
strsource+="\r\n";
}
myHttpFile->Close();
mySession.Close();

strsource存储的就是html源代码。

回答2:

1.读取html文件
2.字符串处理