c#获取网页代码、数据、资源
2024-09-22 06:37:54
//WebClient取网页源码
private string GetHtmlSource(string Url)
{
try
{
System.Net.WebClient wc = new System.Net.WebClient();
wc.Headers["Accept-Language"] = "zh-cn";
wc.Encoding = Encoding.GetEncoding("utf-8"); return wc.DownloadString(Url);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return "";
}
}
除了DownloadString,WebClient还有DownloadFile和DownloadData两个函数。可以下载数据和文件。而DownloadString可以下载uri对应的网页代码。
留文备用。
最新文章
- Spark高级数据分析中文版-读者交流
- 字符串表达式String Expressions
- C:指针、数据类型、格式化输入输出、输入函数的坑点
- OCP读书笔记(13) - 管理内存
- @+android:id的一些记录
- css全局样式表
- java类集框架(ArrayList,LinkedList,Vector区别)
- 五 : springMVC拦截器
- LeetCode算法题-Find Pivot Index(Java实现)
- ZabbixServer安装
- Visible Lattice Points SPOJ - VLATTICE 三维+莫比乌斯反演
- MFC控件编程之鼠标跟键盘消息
- [EXP]Joomla! Component Easy Shop 1.2.3 - Local File Inclusion
- CentOS下SSH远程免密登录服务器
- Js_获取当前日期时间
- rabbitmq route
- Python入门之logging模块
- Python3 集合(set)(十五)
- jQuery基础笔记(3)
- C和C++中的不定参数