vc++ 读取网页源代码

来源:互联网 发布:旧版淘宝下载 编辑:程序博客网 时间:2024/05/16 15:18

CInternetSession session;
 CHttpFile *file = NULL;
 CString strURL ="www.baidu.com";
 CString strHtml = "";   //存放网页数据
 
 try
 {
  file = (CHttpFile*)session.OpenURL(strURL);
 }
 catch(CInternetException * m_pException)
 {
  
  file = NULL;
  m_pException->m_dwError;
  m_pException->Delete();
  session.Close();
  MessageBox("CInternetException");
 }
 
 CString strLine;
 
 if(file != NULL)
 {
  while(file->ReadString(strLine) != NULL)
  {
   strHtml += strLine;
   strHtml +="/r/n";
  }
  MessageBox(strHtml);
 }
 else
 {
  
  MessageBox("fail");
 }
 
 session.Close();
 file->Close();
 delete file;
 file = NULL;