如何只得到<html>和</html>的内容

解决方案 »

  1.   

    解析啊!其他内容的不要了就是!你说的直接得到,也是别人做的http封装!之给你看到<html></html>.
      

  2.   

    How about the processing steps?
      

  3.   

    codeproject 上有篇如何parse html的文章,使用IE的COM接口
      

  4.   

    CString strServerName;
    CString strObject;
    INTERNET_PORT nPort;
    DWORD dwServiceType;
    if (!AfxParseURL(strURL, dwServiceType, strServerName, strObject, nPort) ||
    dwServiceType != INTERNET_SERVICE_HTTP)
    {

    return 1;
    } CSocket socket; if (!socket.Create())
    {
    //cerr << _T("Failed to create CSocket object.") << endl;
    return 1;
    } // cout << _T("Wait... open site: ") << strServerName << endl; if (!socket.Connect(strServerName, nPort))
    {
    //cerr << _T("Can't open site: ") << strServerName << endl;
    return 1;
    } TRY
    {
    int n;
    CString str, strTemp;
    CSocketFile socketFile(&socket);
    CArchive arIn(&socketFile, CArchive::load);
    CArchive arOut(&socketFile, CArchive::store);
    str = "GET " + strObject + " HTTP/1.1\r\n";
    str+="Host:"+strServerName+"\r\n";
    str += szHeaders; str += "\r\n";
    arOut.WriteString(str);
    arOut.Flush(); arIn.ReadString(str);
    if (-1 == (n = str.Find(' ')))
    {
    //错误
    return FALSE;
                }
                if ((strTemp = str.Mid(n + 1, 3)).IsEmpty())
    {

         //错误
    return FALSE;
    }
    if ("200" == strTemp)
    {   
    //赋初值,不读取http头信息,只读取内容
        n = -1;
    while (arIn.ReadString(str) && !str.IsEmpty())
    {
        while (arIn.ReadString(str) && !str.IsEmpty())
    {

         if (0 == str.Find("Content-Length: "))
    {
                  //得到文件的长度
         str = str.Mid(16);
         sscanf(str, "%d", &n);


    }
    }
    if (0 > n)
    {
      
      n = ((DWORD)(-1)) >> 1;
                          
                  //错误
              return FALSE;
    }
                        while ((0 < n) && arIn.ReadString(str))
    {
        m_content+=str;
        n -= (str.GetLength() + 2);

    }
    }
                AfxMessageBox(m_content);
    return TRUE;
    }
    else if (("301" == strTemp) || ("302" == strTemp))
    {

    strURL.Empty();
    while (arIn.ReadString(str) && !str.IsEmpty())
    {
    //cout << str;
    if (0 == str.Find("Location: "))
    {
    strURL = str.Mid(10);
    break;
    }
    }

    }
    }
    CATCH_ALL(e)
    {
    e->Delete();
    //cerr << _T("Abort because of exception.") << endl;
    }
    END_CATCH_ALL

    return TRUE;