Recently on the Internet to find some about the MFC crawl Web page code to see, found that there is a relatively simple code, and you share the next.
CInternetSession session (NULL,0); CHttpFile* Htmlfile =NULL; CString StrLine, strhtml; CString URL= _t ("http://www.tqyb.com.cn/data/gzWeather/gz_weatherForecastInDays.js?"); TCHAR srecv[1024x768]; UINT CodePage=65001;//cp_utf8:65001 cp_acp:0strHTML = _t (""); //get web page source codeHtmlfile = (chttpfile*) session. OpenURL (URL);//re-open the connectionDWORD Dwstatuscode;//Accept Request return valueHtmlfile->QueryInfoStatusCode (Dwstatuscode); if(Dwstatuscode = =HTTP_STATUS_OK) { while(Htmlfile->readstring (SRECV,1024x768)) { //code conversion, can solve the problem of Chinese garbled//gb2312 is converted to Unicode, use CP_ACP//GBK is converted to Unicode, also with CP_ACP//Utf-8 is converted to Unicode, use Cp_utf8 intNbuffersize = MultiByteToWideChar (CodePage,0, (LPCSTR) SRECV,-1Null0); wchar_t*pbuffer =NewWchar_t[nbuffersize +1]; memset (pbuffer,0, (Nbuffersize +1)*sizeof(wchar_t)); //gb2312 is converted to Unicode, use CP_ACP//GBK is converted to Unicode, also with CP_ACP//Utf-8 is converted to Unicode, use Cp_utf8MultiByteToWideChar (CodePage,0, (LPCSTR) SRECV,-1, Pbuffer, nbuffersize*sizeof(wchar_t)); strHTML+=pbuffer; strHTML+="\ r \ n"; Delete pbuffer; }} htmlfile-Close (); Session. Close (); Delete Htmlfile;
Note that this URL code format is UTF8, Chinese will be garbled, so add a character between the conversion,//pagecode = 65001.
And when setting vs, the CharSet is set to multiple characters.
Multi-byte characters, character set, properties---property, project.