Winnet获取网页HTML内容-Code
来源:互联网 发布:淘宝嘉年华有什么折扣 编辑:程序博客网 时间:2024/05/20 16:42
bool loadHtmlFile(const CString& strUrl, CString& strHtml)
{
bool bRet = false;
CInternetSession sess;//建立会话
sess.SetOption(INTERNET_OPTION_CONNECT_TIME, 10*1000, NULL);//似乎不起作用,微软SDK的一个bug
CHttpFile* fileGet = 0;
InternetParam param;
param.pSession = &sess;
param.pHttpFile = &fileGet;
param.strUrl = strUrl;
HANDLE hThread = ::CreateThread(NULL, 0, openUrlProc, (LPVOID)¶m, NULL, NULL);//自己开线程处理超时
DWORD dwTimeOut = 10*1000;
if (::WaitForSingleObject(hThread, dwTimeOut) == WAIT_TIMEOUT)
{
sess.Close();
return false;
}
fileGet = *(param.pHttpFile);
if(fileGet)
{
DWORD dwStatus;
DWORD dwBuffLen = sizeof(dwStatus);
BOOL bSuccess = fileGet->QueryInfo(
HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER,
&dwStatus, &dwBuffLen);
if( bSuccess && dwStatus>= 200 && dwStatus<300 )
{
const int ContentSize = 1024000;//maximin size of text form html file.
char* mbbuf = new char[ContentSize];
int nRead = fileGet->Read(mbbuf, ContentSize-1);
if(nRead > 0 && nRead < ContentSize)
{
mbbuf[nRead] = 0;
int nWordCount = MultiByteToWideChar(CP_ACP, NULL, mbbuf, nRead, NULL, NULL);
if(nWordCount > 0)
{
wchar_t* wstrUnicode = new wchar_t[nWordCount+1];
wstrUnicode[nWordCount] = 0;
MultiByteToWideChar(CP_ACP, NULL, mbbuf, nRead, wstrUnicode, nWordCount+1);
strHtml = wstrUnicode;
delete[] wstrUnicode;
bRet = true;
}
}
delete[] mbbuf;
}
fileGet->Close();
delete fileGet;
}
sess.Close();
return bRet;
}
UNIX主机和WINDOWS主机的回车问题
CString unixRetToWindowRet(const CString& strTxt)//
{
if(strTxt.GetLength() > 0)
{
wchar_t* buf = new wchar_t[strTxt.GetLength()*2+1];
const wchar_t* pSrc = (LPCTSTR)strTxt;
int nCount = 0;
if(pSrc[0] == '/n')
buf[nCount++] = '/r';
buf[nCount++] = pSrc[0];
for(int i = 1; i < strTxt.GetLength(); i++)
{
if(*(pSrc+i) == '/n' && *(pSrc+i-1) != '/r')
buf[nCount++] = '/r';
buf[nCount++] = *(pSrc+i);
}
buf[nCount++] = 0;
return buf;
}
return CString();
}
- Winnet获取网页HTML内容-Code
- VC++中使用使用winnet类获取网页内容
- VC++中使用使用winnet类获取网页内容
- VC++中使用使用winnet类获取网页内容
- 获取HTML网页内容SgmlReader
- 获取html网页的内容
- java获取网页html内容。。。。。。。
- 使用XPath解析HTML获取网页内容
- C# 获取HTML网页内容SgmlReader
- html 获取黏贴的网页内容
- [code]使用正则获取网页里的特定内容
- telnet建立http连接获取网页HTML内容
- telnet建立http连接获取网页HTML内容
- 获取WebView加载HTML时网页中的内容
- js获取网页选中部分的内容,包含html代码
- HTMLPARSER 爬取 html网页 获取标题 关键字 内容 url
- 获取WebView加载HTML时网页中的内容
- 【Jsoup】HTML解析器,轻松获取网页内容
- use-case modeling 培训记录
- 最佳开源软件一览
- 最好的一篇关于Log4j的使用的文章
- java中配置文件的位置和读取
- Asp.net生成htm静态文件的两种途径
- Winnet获取网页HTML内容-Code
- Monitor server hardware. Tools might include Device Manager, the Hardware Troubleshooting Wizard, and appropriate Control Panel
- 公司就是我的“家”(转)
- PB编译原理探讨中......
- 萨苏:对使用原子弹轰炸日本最好的说明
- Regular Expression之CAtlRegExp
- JBuilder 用户的 NetBeans IDE 指南
- Eclipse快捷键指南
- 阿翔编程学-Web Service详细解析及使用方法(全) 包括XFire、Axis