c# 后台隐式使用webBrowser
2024-09-27 17:05:51
c#不使用 webBrowser 控件, 在后台加载html流
private void button1_Click(object sender, EventArgs e)
{
string urlPath = "https://www.cnblogs.com";//
HtmlDocument html = GetHtmlDocument(urlPath);
textBox1.Text = html.Body.InnerHtml;
} //不使用控件中加载html文档
private HtmlDocument GetHtmlDocument(string htmlpath)
{
WebBrowser getInfoWebBrowser = new WebBrowser();
//是否弹出js出错对话框 true 标示不弹对话框
getInfoWebBrowser.ScriptErrorsSuppressed = true;
//把从网络下载的html流赋值给 WebBrowser
/*
* WebRequest.Create(htmlpath).GetResponse().GetResponseStream();
* 从指定网址下载资源
*
*/
getInfoWebBrowser.DocumentStream = WebRequest.Create(htmlpath).GetResponse().GetResponseStream();
HtmlDocument html = getInfoWebBrowser.Document;
//让程序处理当前消息 [不可少]
Application.DoEvents();
//释放资源
getInfoWebBrowser.Dispose();
return html;
}
最新文章
- AFNetwork ATS 网络层改造
- <;实训|第五天>;通过搭建NFS,FTP实现共享文件附Vim脚本游戏
- PLSQL开发笔记和小结(转载)
- codeforces 489C.Given Length and Sum of Digits... 解题报告
- Visual Studio 2012 使用免费的Team Foundation Service
- redis 订阅与发布
- 匹配替换第n个字符串
- Linux入门(11)——Ubuntu16.04安装texlive2016并配置texmaker和sublime text3
- HDU 6121 Build a tree(找规律+模拟)
- 正确使用volatile场景--状态标志
- SSM整合(2): spring 与 mybatis 整合
- post请求(headers里有属性)报错:Request header field xxx is not allowed by Access-Control-Allow-Headers in preflight response
- The Activities of September
- Storm实现实时大数据分析
- [BZOJ5109]大吉大利,晚上吃鸡!
- vim选择命令
- 偏前端 + rsa加解密 + jsencrypt.min.js--(新增超长字符分段加解密)
- centos 查看mysql数据库命令
- React 常用面试题目与分析
- R语言初识
热门文章
- SpringCloud-Config通过Java访问URL对敏感词加密解密
- spark 常用函数介绍(python)
- Flutter常见数据类型及数据类型转换
- [Ubuntu]18安装navicat 破解版&;官方版本
- 一百零二:CMS系统之sweetalert提示框和使用
- selenium 2019 笔记
- CentOS7出现Unit iptables.service could not be found
- Python之Numpy:二元函数绘制/三维数据可视化/3D
- Mac运行React Native安卓项目报错解决
- SQL SERVER CLR Trigger功能