MFC获取网页的html文本

使用 CInternetSession 类和 CHttpFile 类;

在stdafx.h中加入 #include <afxinet.h> ;

基本的代码如下,

cpp 复制代码
void CMFCApplication3Dlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	try
	{
		CInternetSession session;
		CHttpFile* file = (CHttpFile*)session.OpenURL(_T("http://localhost/"));

		//读取数据
		CString content;
		CString temp;
		while (file->ReadString(temp))
		{
			content += temp;
		}

		//网络流一般是UTF8 需要转换
		CString convert = CA2T((LPCSTR)content.GetBuffer());
		m_edit.SetWindowText(convert);

		//释放资源
		file->Close();
		session.Close();
		delete file;
	}
	catch (CInternetException* e)//异常处理
	{
		TCHAR sz[512] = { 0 };
		e->GetErrorMessage(sz, 512);
		AfxOutputDebugString(sz);
		e->Delete();
	}
}

进一步可以查找一些字符串等;

有时间继续;

相关推荐
朔北之忘 Clancy1 小时前
2025 CSP-J 第二轮真题解析
c++·青少年编程·题解·noip·csp·信奥赛·noi
longlongzihan1 小时前
LeetCode 17电话号码的字母组合:回溯算法(DFS)详解
c++·算法·leetcode·深度优先
yolo_guo1 小时前
调试mysql延迟与libevent回调实际发送回复时机问题
c++·mysql·libevent
今晚打老虎2 小时前
c++之提高A(前缀和)(第三课)
数据结构·c++·算法
by209994 小时前
从结构体到对象:正式学习C++类的骨架、封装与this指针
c++·经验分享·学习
2601_962218614 小时前
C语言中三种库的编译和使用方法
开发语言·c++
jimy15 小时前
派生类重写基类虚函数(二):override的作用
开发语言·c++
ebiobiz5 小时前
基于 GD32 Embedded Builder (GEB) 与 Nimmake 的 MCU 工程搭建指南
c++·python·单片机·嵌入式硬件·mcu
hetao17338375 小时前
2026-09-29 hetao1733837 的刷题记录
c++·算法
:mnong5 小时前
几何内核“四大金刚“:ACIS、Parasolid、CGM、Open CASCADE 核心特征深度解析
c++·cad·cax