64,654
社区成员
发帖
与我相关
我的任务
分享
bool GetSourceHtml(char* theUrl )
{
HINTERNET IN hOpen= InternetOpen(_T("MSDN"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
DWORD dwSize;
const char* szHead = "Accept: */*\r\n\r\n";
char szTemp[5000];
HINTERNET hConnect;
if ( !(hConnect = InternetOpenUrl ( hOpen,(LPCWSTR) theUrl, (LPCWSTR )szHead,_tcslen(szHead), INTERNET_FLAG_FROM_CACHE, 0)))
{
return false;
}
string str;
do
{
if (!InternetReadFile (hConnect, szTemp, 5000, &dwSize) )
{
return false;
}
if (!dwSize)
return false; // Condition of dwSize=0 indicate EOF. Stop.
else
{
string temp;
sprintf(temp,_T("%s"),szTemp);
str+=temp;
}
// fwrite(szTemp, sizeof (char), dwSize , pFile);
}
while (TRUE);
::InternetCloseHandle(hConnect) ;
::InternetCloseHandle(hOpen) ;
wchar_t* pWChar = NULL;
DWORD nLen1;
// 将网页UTF-8格式编码转换成Unicode
nLen1 = MultiByteToWideChar(CP_UTF8,0,str,str.length(),pWChar,0);
pWChar = new wchar_t[nLen1 + 1];
memset(pWChar,0,(nLen1 + 1 ) * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8,0,str,str.length(),pWChar,nLen1);
char* pChar = NULL;
DWORD nLen2;
nLen2 = WideCharToMultiByte(CP_ACP,0,pWChar,nLen1,pChar,0,NULL,NULL);
pChar = new char[nLen2 + 1];
memset(pChar,0, nLen2 + 1);
WideCharToMultiByte(CP_ACP,0,pWChar,nLen1,pChar,nLen2,NULL,NULL);
sprintf(str,_T("%s"),pChar);// str.Format(_T("%s"),pChar);
delete pChar;
delete pWChar;
const std::tr1::regex pattern("style=\"\" href=\".*?\"");
std::string weekend =str;
std::string strSql;
const std::tr1::sregex_token_iterator end;
for (std::tr1::sregex_token_iterator i(weekend.begin(),
weekend.end(), pattern);
i != end;
++i)
{
std::string strtemp=*i;
// replace_all_distinct(strtemp,"'","''");
strSql+="insert into tbcsdn values(,'"+strtemp+"'getData());";
}
myado.Init();
if(myado.ExecuteSQL(strSql.c_str()))
MsgBox(_T("成功!"));
else
MsgBox(_T("失败!!!"));
return true;
}
1>d:\documents and settings\administrator\my documents\visual studio 2008\projects\qq\qq\qq.cpp(111) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> d:\program files\microsoft visual studio 9.0\vc\include\string.h(157) : 参见“strncpy”的声明
1>d:\documents and settings\administrator\my documents\visual studio 2008\projects\qq\qq\qq.cpp(154) : error C2664: “wcslen”: 不能将参数 1 从“const char *”转换为“const wchar_t *”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
1>d:\documents and settings\administrator\my documents\visual studio 2008\projects\qq\qq\qq.cpp(173) : error C2664: “sprintf”: 不能将参数 1 从“std::string”转换为“char *”
1> 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
1>d:\documents and settings\administrator\my documents\visual studio 2008\projects\qq\qq\qq.cpp(188) : error C2664: “MultiByteToWideChar”: 不能将参数 3 从“std::string”转换为“LPCSTR”
1> 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
1>d:\documents and settings\administrator\my documents\visual studio 2008\projects\qq\qq\qq.cpp(191) : error C2664: “MultiByteToWideChar”: 不能将参数 3 从“std::string”转换为“LPCSTR”
1> 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
1>d:\documents and settings\administrator\my documents\visual studio 2008\projects\qq\qq\qq.cpp(201) : error C2664: “sprintf”: 不能将参数 1 从“std::string”转换为“char *”
1> 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
bool GetSourceHtml(TCHAR* theUrl )
{
HINTERNET IN hOpen= InternetOpen(_T("MSDN"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
DWORD dwSize;
const TCHAR* szHead = _T("Accept: */*\r\n\r\n");
char szTemp[500];
HINTERNET hConnect;
if ( !(hConnect = InternetOpenUrl ( hOpen,(LPCWSTR) theUrl, (LPCWSTR )szHead,_tcslen(szHead), INTERNET_FLAG_RELOAD, 0)))
{
return false;
}
string str;
do
{
if (!InternetReadFile (hConnect, szTemp, 500, &dwSize) )
{
return false;
}
if (!dwSize)
break; // Condition of dwSize=0 indicate EOF. Stop.
else
{
string temp=string(szTemp);
// sprintf(temp,_T("%s"),szTemp);
str+=temp;
}
// fwrite(szTemp, sizeof (TCHAR), dwSize , pFile);
}
while (TRUE);
::InternetCloseHandle(hConnect) ;
::InternetCloseHandle(hOpen) ;
wchar_t* pWChar = NULL;
DWORD nLen1;
// 将网页UTF-8格式编码转换成Unicode
nLen1 = MultiByteToWideChar(CP_UTF8,0,str.c_str(),str.length(),pWChar,0);
pWChar = new wchar_t[nLen1 + 1];
memset(pWChar,0,(nLen1 + 1 ) * sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8,0,str.c_str(),str.length(),pWChar,nLen1);
char* pChar = NULL;
DWORD nLen2;
nLen2 = WideCharToMultiByte(CP_ACP,0,pWChar,nLen1,pChar,0,NULL,NULL);
pChar = new char[nLen2 + 1];
memset(pChar,0, nLen2 + 1);
WideCharToMultiByte(CP_ACP,0,pWChar,nLen1,pChar,nLen2,NULL,NULL);
str=string(pChar);
// sprintf(str,_T("%s"),pChar);// str.Format(_T("%s"),pChar);
delete pChar;
delete pWChar;
const std::tr1::regex pattern("style=\"\" href=\"(.*?)\"");
std::string weekend =str;
std::string strSql;
const std::tr1::sregex_token_iterator end;
for (std::tr1::sregex_token_iterator i(weekend.begin(),
weekend.end(), pattern);
i != end;
++i)
{
std::string strtemp=*i;
// replace_all_distinct(strtemp,"'","''");
strSql+="insert into tbcsdn values('"+strtemp+"',getDate());";
}
myado.Init();
if(myado.ExecuteSQL(strSql.c_str()))
MsgBox(_T("成功!"));
else
MsgBox(_T("失败!!!"));
return true;