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 ...
随机推荐
- NOI 2018 归程 (Kruskal重构树)
题目大意:太长了,略 Kruskal重构树,很神奇的一个算法吧 如果两个并查集被某种条件合并,那么这个条件作为一个新的节点连接两个并查集 那么在接下来的提问中,如果某个点合法,它的所有子节点也都合法, ...
- v4l2程序实例
#include <stdio.h> #include <string.h> #include <errno.h> #include <stdlib.h> ...
- url中jsessionid的理解
(1) 这是一个保险措施 因为Session默认是需要Cookie支持的 但有些客户浏览器是关闭Cookie的 这个时候就需要在URL中指定服务器上的session标识,也就是5F4771183629 ...
- angular-数据库
<div ng-app="myApp" ng-controller="customersCtrl"> <table> <tr ng ...
- 洛谷——P2822 组合数问题
https://www.luogu.org/problem/show?pid=2822 题目描述 组合数C_n^mCnm表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三 ...
- Bing地图切片原理
Bing地图切片系统 Bing地图提供了一个可以直接平移和缩放的世界地图.为了让地图操作更加平滑和及时响应,我们选择提前渲染地图不同层级的细节,并把每个层级的地图切割成为瓦片以便快速的还原展示.这篇文 ...
- Could not connect to SMTP host: localhost, port: 25;
1.错误描写叙述 DEBUG: setDebug: JavaMail version 1.3.3 DEBUG: getProvider() returning javax.mail.Provider[ ...
- JDBC-连接数据库代码
package com.zxc.connection; import java.sql.Connection; import java.sql.DriverManager; public class ...
- 换今日特价图片---轻开电子商务系统(企业入门级B2C站点)
跟换主页轮播图片一样,一共4个文件: 列表显示文件:site/links/img2.html 加入图片文件:site/links/img2_add.html 加入保存图片文件:site/links/i ...
- STL 之 iterator traits 备忘
//5种迭代器.为了激活重载机制,定义的5个类型.每种迭代器就是一个类型. struct input_iterator_tag{}; struct output_iterator_tag{}; str ...