码迷,mamicode.com
首页 > 编程语言 > 详细

C++ 获取网页源码码的操作

时间:2014-08-09 11:33:47      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:style   http   os   io   for   ar   amp   c++   

#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#pragma comment(lib,"Wininet.lib")
#include <vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<TCHAR> v;
TCHAR szUrl[] = _T("http://www.95server.com/");
TCHAR szAgent[] = _T("");
HINTERNET hInternet1 =
InternetOpen(NULL,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);
if (NULL == hInternet1)
{
InternetCloseHandle(hInternet1);
printf("%s\n","NULL == hInternet1");
return FALSE;
}
HINTERNET hInternet2 =
InternetOpenUrl(hInternet1,szUrl,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE,NULL);
if (NULL == hInternet2)
{
InternetCloseHandle(hInternet2);
InternetCloseHandle(hInternet1);
printf("%s\n","NULL == hInternet2");
return FALSE;
}
DWORD dwMaxDataLength = 500;
PBYTE pBuf = (PBYTE)malloc(dwMaxDataLength*sizeof(TCHAR));
if (NULL == pBuf)
{
InternetCloseHandle(hInternet2);
InternetCloseHandle(hInternet1);
printf("%s\n","NULL == pBuf");
return FALSE;
}
DWORD dwReadDataLength = NULL;
BOOL bRet = TRUE;
do
{
ZeroMemory(pBuf,dwMaxDataLength*sizeof(TCHAR));
bRet = InternetReadFile(hInternet2,pBuf,dwMaxDataLength,&dwReadDataLength);
for (DWORD dw = 0;dw < dwReadDataLength;dw++)
{
v.push_back(pBuf[dw]);
}
} while (NULL != dwReadDataLength);
vector<TCHAR>::iterator i;
for(i=v.begin(); i!=v.end(); i++)
printf("%c",*i);
return 0;
}

C++ 获取网页源码码的操作,布布扣,bubuko.com

C++ 获取网页源码码的操作

标签:style   http   os   io   for   ar   amp   c++   

原文地址:http://www.cnblogs.com/minggeqiuzhi/p/3900700.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!