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 ...
随机推荐
- python 进程 multiprocessing模块
一.multiprocess.process模块 1.process类 Process([group [, target [, name [, args [, kwargs]]]]]),由该类实例化得 ...
- 页面关闭或刷新时触发javascript的事件
当页面在关闭或刷新时提示 window.onbeforeunload(function(){ //判断是关闭还是刷新 1.满足关闭,否则是刷新 if(event.clientX>document ...
- 封装HttpClient进行http请求与https请求
一.https忽略证书 /** * 用于进行Https请求的HttpClient * * @author joey * */ public class SSLClient { public stati ...
- 循环语句第2种 WHILE ... LOOP END LOOP;
--------第2种-------- WHILE ... LOOP END LOOP; declare n number(3) :=1; begin WHILE n&l ...
- Nutch2 WebPage 字段解释
Nutch2 WebPage 字段解释 Nutch2.2.1 id
- Oracle Study之--Oracle 单实例11.2.0.1.0升级到11.2.0.3.0
Oracle Study之--Oracle 单实例11.2.0.1.0升级到11.2.0.3.0 系统环境: 操作系统:RedHat EL6(64位) Oracle: Oracle 11gR2 ...
- Java5新特性之枚举
1. 概念 首先,枚举并非一种新技术,而是一种基础数据类型.它隶属于两种基础类型中的值类型,例如以下: 2. 为什么要有枚举 枚举在真正的开发中是非经常常使用的,它的作用非常easy也非常纯粹:它 ...
- AspNet WebApi 中应用fo-dicom抛出异常:No codec registered for tranfer syntax:
背景: 在做一个Dicom Web Service, 当中WADO-RS中须要解析TransferSyntax, 然后就用到了fo-dicom中的DicomFile.ChangeTransferSyn ...
- android:异步任务asyncTask介绍及异步任务下载图片(带进度条)
为什么要用异步任务? 在android中仅仅有在主线程才干对ui进行更新操作.而其他线程不能直接对ui进行操作 android本身是一个多线程的操作系统,我们不能把全部的操作都放在主线程中操作 .比方 ...
- C++ 虚函数的缺省參数问题
前些日子,有个同学问我一个关于虚函数的缺省參数问题.他是从某个论坛上看到的.可是自己没想通.便来找我. 如今分享一下这个问题.先看一小段代码: #include <iostream> us ...