MFC抓网页

 CString chinachar_str("读取的东西:");
    CInternetSession sion(NULL,0); 
    CHttpFile *http=NULL; 
    CString str,info; 
    http=(CHttpFile*)sion.OpenURL(_T("http://www.baidu.com")); 

    while (http->ReadString(str)) 
    { 
        info+=str;//取读取的数据 
    } 
    ConvertUtf8ToGBK(info);
    LPCTSTR mystr =info; //把CString类型转换为char* 类型
    for (int i=0;mystr[i];i++)
    {
        if (mystr[i] < 0) //一个中文占两个字节,且每个字节都是小于0的
        {
            CString tmp;
            tmp.Format("%c%c",mystr[i],mystr[i+1]);//把中文输出,举个例子
            i++;
            chinachar_str=chinachar_str+tmp;
        }
    }
    m_edit.SetWindowText(chinachar_str);
    UpdateData(FALSE); 
    http->Close(); 
    sion.Close();

    int  f = chinachar_str.Find( "百度" ) ;    // 结果 f = 3
    if(f!=-1)
    {
        AfxMessageBox("find ");
    }

 

posted on 2016-05-17 13:27  mitutao  阅读(240)  评论(0编辑  收藏  举报

导航