当前位置:AIGC资讯 > 数据采集 > 正文

用c语言实现网络爬虫,C语言编写网络爬虫

C语言编写网络爬虫

#include

#include

#include

#include

#pragma comment(lib, "ws2_32.lib")//加载网络支持的库

#define _M_MPPC

using namespace std;

/************************************************************************/ /* 数据获取类

/************************************************************************/ class Net

{

public:

int UTF8ToGBK(unsigned char * lpUTF8Str,unsigned char * lpGBKStr,int nGBKStrLen);//UTF8转GBK

char *UTOG(char *lpUTF8Str);

string geturl(char *url);

};

int Net::UTF8ToGBK(unsigned char * lpUTF8Str,unsigned char * lpGBKStr,int nGBKStrLen) {

wchar_t * lpUnicodeStr = NULL;

int nRetLen = 0;

if(!lpUTF8Str)

return 0;

nRetLen = ::MultiByteToWideChar(CP_UTF8,0,(char *)lpUTF8Str,-1,NULL,NULL); lpUnicodeStr = new WCHAR[nRetLen + 1];

nRetLen = ::MultiByteToWideChar(CP_UTF8,0,(char *)lpUTF8Str,-1,lpUnicodeStr,nRetLen); if(!nRetLen)

return 0;

nRetLen = ::WideCharToMultiByte(CP_ACP,0,lpUnicodeStr,-1,NULL,NULL,NULL,NULL); if(!lpGBKStr)

{

if(lpUnicodeStr)

delete []lpUnicodeStr;

return nRetLen;

}

if(nGBKStrLen < nRetLen)

{

if(lpUnicodeStr)

delete []lpUnicodeStr;

return 0;

}

nRetLen = ::WideCharToMultiByte(CP_ACP,0,lpUnicodeStr,-1,(char

更新时间 2023-11-08