MFC crawl Web page code simple version.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.