asp.net C# 获取网页源代码的几种方式
1 方法
- System.Net.WebClient aWebClient = new System.Net.WebClient();
- aWebClient.Encoding = System.Text.Encoding.Default;
- Byte[] pageData = aWebClient.DownloadData(url);
- string nhtml = Encoding.GetEncoding("utf-8").GetString(pageData);
2方法
- System.Net.WebClient aWebClient = new System.Net.WebClient();
- aWebClient.Encoding = System.Text.Encoding.Default;
- string nhtml = aWebClient.DownloadString(goodstidurl);
3方法
- WebBrowser webbrowser = new WebBrowser();
- StreamReader sr = new StreamReader(this.webBTaobao.DocumentStream, Encoding.Default);
- html = sr.ReadToEnd();
- html = html.Replace("\r\n", "");
- html = html.Replace("\n", "");
- html = html.Replace(" ", "");
- html = html.Replace("(", "");
- html = html.Replace(")", "");
- string nurl = Regex.Match(html, "(?<=data-url=\").*?(?=\")").Value;
- //新建一个WebBrowser
- WebBrowser webAddress = new WebBrowser();
- webAddress.Navigate(nurl);
- //等待载入完毕
- while (webAddress.ReadyState < WebBrowserReadyState.Complete) Application.DoEvents();
- StreamReader sraddress = new StreamReader(webAddress.DocumentStream, Encoding.Default);
- jsonaddress = sraddress.ReadToEnd();
4方法
- WebRequest hwr = WebRequest.Create(@"http://item.taobao.com/item.htm?
- id=" + row["urlId"].ToString());//向指定Url发出请求
- HttpWebResponse hwp = hwr.GetResponse() as HttpWebResponse;//将hwr对HTTP的请求
- string text;
- StreamReader sr;
- string code = hwp.ContentType;//请求响应得到的内容类型
- //得到编码了
- code = code.Split('=')[1];
- Stream rep = hwp.GetResponseStream();//将请求得到的内容以流的形式读出
- sr = new StreamReader(rep, Encoding.GetEncoding(code));//用指定的字符编码为指定的流初始化
asp.net C# 获取网页源代码的几种方式的更多相关文章
- Python 2.7获取网站源代码的几种方式_20160924
#coding:utf-8 import urllib2,cookielib if __name__ == '__main__': root_url='https://www.baidu.com/' ...
- c#利用WebClient和WebRequest获取网页源代码的比较
前几天举例分析了用asp+xmlhttp获取网页源代码的方法,但c#中一般是可以利用WebClient类和WebRequest类获取网页源代码.下面分别说明这两种方法的实现. WebClient类获取 ...
- Java 网络爬虫获取网页源代码原理及实现
Java 网络爬虫获取网页源代码原理及实现 1.网络爬虫是一个自动提取网页的程序,它为搜索引擎从万维网上下载网页,是搜索引擎的重要组成.传统爬虫从一个或若干初始网页的URL开始,获得初始网页上的URL ...
- delphi 获取网页源代码
//获取网页源代码 var s: string; begin s := WebBrowser1.OleObject.document.body.innerHTML; //body内的所有代码 ...
- JS远程获取网页源代码的例子
js代码获取网页源代码. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> < ...
- c#利用WebClient和WebRequest获取网页源代码
C#中一般是可以利用WebClient类和WebRequest类获取网页源代码.下面分别说明这两种方法的实现. WebClient类获取网页源代码 WebClient类 WebClient ...
- c#利用HttpWebRequest获取网页源代码
c#利用HttpWebRequest获取网页源代码,搞了好几天终于解决了,直接获取网站编码进行数据读取,再也不用担心乱码了! 命名空间:Using System.Net private static ...
- js技术要点---JS 获取网页源代码
JS 获取网页源代码 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html& ...
- C# 获取网页源代码
/// <summary> /// 获取网页源代码 /// </summary> /// <param name="url"></para ...
随机推荐
- LVS负载均衡三种模式的实现
何为lvs负载均衡? lvs负载均衡(linux virtual server)又名linux虚拟服务器.由章文嵩博士主导的负载均衡项目,目前LVS已经被集成到Linux内核模块中.该项目在Linux ...
- typedef和define混用产生的错误
最近在写代码过程中,发现一个问题,编译总是过不去,报错如下: stdint.h::: error: duplicate 'unsigned' stdint.h::: error: 'long long ...
- MarkDown、Vim双剑合璧
作为一名软件攻城狮(是的,我从来都以攻城狮自居! 我坚信如今的每一天,都在朝攻城狮迈进.虽然被菜鸟的肉身皮囊裹着,我依然还是怀着攻城狮的内心! 我非常讨厌别人喊我程序猿.虽然这是不争的事实!).... ...
- HDU 5305 Friends (搜索+剪枝) 2015多校联合第二场
開始对点搜索,直接写乱了.想了想对边搜索,尽管复杂度高.剪枝一下水过去了. 代码: #include<cstdio> #include<iostream> #include&l ...
- 广播BroadcastReceiver(2)
有序广播的优先级: 发送有序广播的方法有: public void sendOrderedBroadcast(Intent intent,String receiverPermis ...
- ZOJ 3689 Digging(贪心+dp)
Digging Time Limit: 2 Seconds Memory Limit: 65536 KB When it comes to the Maya Civilization, we ...
- web程序定时器
package com.timer; import java.util.Calendar; import java.util.Date; import java.util.Timer; import ...
- Oracle 学习笔记 13 -- 控制用户权限
数据库控制语言的功能室控制用户对数据库的存取权限. 用户对某类数据具有何种操作权限是有DBA决定的.Oracle 通过GRANT语句完毕权限的授予,通过REVOKE语句完毕对权限的收回. 权限分为系统 ...
- 关于webuploader跨域解决方法
1.在iis处理程序映射 2.后台ashx处理添加如下代码
- kettle工具的设计原则
不多说,直接上干货! Kettle工具在设计初,就考虑到了一些设计原则.这些原则里借鉴了以前使用过的其他一些ETL工具积累下的经验和教训. 易于开发:作为数据仓库和ETL开发者,你只想把时间用在创建B ...