1 方法

  1. System.Net.WebClient aWebClient = new System.Net.WebClient();
  2. aWebClient.Encoding = System.Text.Encoding.Default;
  3. Byte[] pageData = aWebClient.DownloadData(url);
  4.  
  5. string nhtml = Encoding.GetEncoding("utf-8").GetString(pageData);

2方法

  1. System.Net.WebClient aWebClient = new System.Net.WebClient();
  2. aWebClient.Encoding = System.Text.Encoding.Default;
  3. string nhtml = aWebClient.DownloadString(goodstidurl);

3方法

  1. WebBrowser webbrowser = new WebBrowser();
  2. StreamReader sr = new StreamReader(this.webBTaobao.DocumentStream, Encoding.Default);
  3. html = sr.ReadToEnd();
  4. html = html.Replace("\r\n", "");
  5. html = html.Replace("\n", "");
  6. html = html.Replace(" ", "");
  7. html = html.Replace("(", "");
  8. html = html.Replace(")", "");
  9. string nurl = Regex.Match(html, "(?<=data-url=\").*?(?=\")").Value;
  10. //新建一个WebBrowser
  11. WebBrowser webAddress = new WebBrowser();
  12. webAddress.Navigate(nurl);
  13. //等待载入完毕
  14. while (webAddress.ReadyState < WebBrowserReadyState.Complete) Application.DoEvents();
  15. StreamReader sraddress = new StreamReader(webAddress.DocumentStream, Encoding.Default);
  16. jsonaddress = sraddress.ReadToEnd();

4方法

  1. WebRequest hwr = WebRequest.Create(@"http://item.taobao.com/item.htm?
  2.  
  3. id=" + row["urlId"].ToString());//向指定Url发出请求
  4. HttpWebResponse hwp = hwr.GetResponse() as HttpWebResponse;//将hwr对HTTP的请求
  5. string text;
  6. StreamReader sr;
  7. string code = hwp.ContentType;//请求响应得到的内容类型
  8. //得到编码了
  9. code = code.Split('=')[1];
  10. Stream rep = hwp.GetResponseStream();//将请求得到的内容以流的形式读出
  11. 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. LVS负载均衡三种模式的实现

    何为lvs负载均衡? lvs负载均衡(linux virtual server)又名linux虚拟服务器.由章文嵩博士主导的负载均衡项目,目前LVS已经被集成到Linux内核模块中.该项目在Linux ...

  2. typedef和define混用产生的错误

    最近在写代码过程中,发现一个问题,编译总是过不去,报错如下: stdint.h::: error: duplicate 'unsigned' stdint.h::: error: 'long long ...

  3. MarkDown、Vim双剑合璧

    作为一名软件攻城狮(是的,我从来都以攻城狮自居! 我坚信如今的每一天,都在朝攻城狮迈进.虽然被菜鸟的肉身皮囊裹着,我依然还是怀着攻城狮的内心! 我非常讨厌别人喊我程序猿.虽然这是不争的事实!).... ...

  4. HDU 5305 Friends (搜索+剪枝) 2015多校联合第二场

    開始对点搜索,直接写乱了.想了想对边搜索,尽管复杂度高.剪枝一下水过去了. 代码: #include<cstdio> #include<iostream> #include&l ...

  5. 广播BroadcastReceiver(2)

    有序广播的优先级:        发送有序广播的方法有:    public void sendOrderedBroadcast(Intent intent,String receiverPermis ...

  6. ZOJ 3689 Digging(贪心+dp)

    Digging Time Limit: 2 Seconds      Memory Limit: 65536 KB When it comes to the Maya Civilization, we ...

  7. web程序定时器

    package com.timer; import java.util.Calendar; import java.util.Date; import java.util.Timer; import ...

  8. Oracle 学习笔记 13 -- 控制用户权限

    数据库控制语言的功能室控制用户对数据库的存取权限. 用户对某类数据具有何种操作权限是有DBA决定的.Oracle 通过GRANT语句完毕权限的授予,通过REVOKE语句完毕对权限的收回. 权限分为系统 ...

  9. 关于webuploader跨域解决方法

    1.在iis处理程序映射 2.后台ashx处理添加如下代码

  10. kettle工具的设计原则

    不多说,直接上干货! Kettle工具在设计初,就考虑到了一些设计原则.这些原则里借鉴了以前使用过的其他一些ETL工具积累下的经验和教训. 易于开发:作为数据仓库和ETL开发者,你只想把时间用在创建B ...