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# 获取网页源代码的几种方式的更多相关文章

  1. Python 2.7获取网站源代码的几种方式_20160924

    #coding:utf-8 import urllib2,cookielib if __name__ == '__main__': root_url='https://www.baidu.com/' ...

  2. c#利用WebClient和WebRequest获取网页源代码的比较

    前几天举例分析了用asp+xmlhttp获取网页源代码的方法,但c#中一般是可以利用WebClient类和WebRequest类获取网页源代码.下面分别说明这两种方法的实现. WebClient类获取 ...

  3. Java 网络爬虫获取网页源代码原理及实现

    Java 网络爬虫获取网页源代码原理及实现 1.网络爬虫是一个自动提取网页的程序,它为搜索引擎从万维网上下载网页,是搜索引擎的重要组成.传统爬虫从一个或若干初始网页的URL开始,获得初始网页上的URL ...

  4. delphi 获取网页源代码

    //获取网页源代码 var   s: string; begin   s := WebBrowser1.OleObject.document.body.innerHTML; //body内的所有代码 ...

  5. JS远程获取网页源代码的例子

    js代码获取网页源代码. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> < ...

  6. c#利用WebClient和WebRequest获取网页源代码

    C#中一般是可以利用WebClient类和WebRequest类获取网页源代码.下面分别说明这两种方法的实现.   WebClient类获取网页源代码   WebClient类   WebClient ...

  7. c#利用HttpWebRequest获取网页源代码

    c#利用HttpWebRequest获取网页源代码,搞了好几天终于解决了,直接获取网站编码进行数据读取,再也不用担心乱码了! 命名空间:Using System.Net private static ...

  8. js技术要点---JS 获取网页源代码

    JS 获取网页源代码 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html& ...

  9. C# 获取网页源代码

    /// <summary> /// 获取网页源代码 /// </summary> /// <param name="url"></para ...

随机推荐

  1. [luogu1772 ZJOI2006] 物流运输 (最短路 线性dp)

    题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输过程实施严格的管理和跟踪. ...

  2. Linux进程僵死原因排查思路

    常情况下脚本执行时间几秒完成,如果超过很长时间执行完成,可能是进程等待某些资源引起阻塞(假死状态). 场景:xx.perl读取文件并发送邮件 现象:执行脚本的进程僵死(卡住) 排查:ps -ef |g ...

  3. python3 列表操作

    - 创建列表 #创建列表: list1 = [1, 2, 3, 4, 5] - 向列表中添加元素 - append # 向列表中添加元素: list1 = [1, 2, 3, 4, 5] list1. ...

  4. thinkphp 多个字段的不同关系的查询条件实现 .

    tp的$map不同条件默认是 and ,如果要用or<><><><>如下 例如查询Stu表中年龄大于18,或者身高低于180cm的男性(1为男性),(例 ...

  5. HDU 1350 Taxi Cab Scheme

    Taxi Cab Scheme Time Limit: 10000ms Memory Limit: 32768KB This problem will be judged on HDU. Origin ...

  6. 第八章 Servlet概述

    第八章 Servlet概述 主要内容: 了解servlet: 掌握servlet实现: 掌握servlet的生命周期. servlet概念 Servlet是运行在服务器端用Java语言编写的应用程序, ...

  7. Ruby中写换行

    Ruby中写换行 print("Hello,\nRuby\n!\n") print("Hello, Ruby ! ") 这两个竟然是一样的:就是说,可以直接回车 ...

  8. org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\Java\jdk1.7.0_7

    32为的androidstudio: build.gradle: dexOptions { javaMaxHeapSize "1g"}

  9. sicily 1091 Maximum Sum (动规)

    //1091.Maximum Sum //b(i,j) = max{b(i,j-1)+a[j], max(b(i-1,t)+a[j])} (t<j) #include <iostream& ...

  10. R和中心度、中心势

    最近用R画论文里的弦图,恰好借的书里着重写了中心度等问题. 网上流行一套密歇根大学社交计算的教程.但是前两年看了好几遍总是搞不清,即便是记公式也是收效不大.不妨按照书上总结一下. 绝对法: 无向图点度 ...