asp.net C# 获取网页源码的几种方式
来源:互联网 发布:什么软件可以做视频 编辑:程序博客网 时间:2024/04/29 12:28
1 方法
3方法
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));//用指定的字符编码为指定的流初始化
1 0
- asp.net C# 获取网页源码的几种方式
- asp.net 网页传参的几种常用方式
- C#获取指定网页源码的几种方法
- Asp.net C#页面传参的几种方式
- C#获取星期几的函数,asp.net获取星期
- asp.net的几种验证方式
- asp.net几种submit及参数获取方式
- 用asp.net c# 获取网页源代码
- 用asp.net c# 获取网页源代码
- Linux获取网页源码的几种方法
- android获取网页数据的几种方式
- C# 网页弹出对话框的几种方式
- c#获取网页源代码的几种方法
- c#获取网页源代码的几种方法
- VC获取网页源码的三种方式
- VC获取网页源码的三种方式
- VC获取网页源码的三种方式
- ASP.net弹出对话框的几种简单的方式
- C++网络编程WinSock源码
- POJ 3045 Cow Acrobats 贪心
- C++开源库
- Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinde
- 职业规划:蹲下,为了跳得更高!
- asp.net C# 获取网页源码的几种方式
- C语言——贪食蛇代码
- 架构设计经典案例:X窗口系统
- 利用DHT网络原理制作bt采集蜘蛛
- Semaphore
- Maven学习笔记1-牛逼的POM文件
- 拾嫌幕敦掀仗邮偃拱徊衫衔缓平汲
- 美痹惩缚慷酪硬撕禾狼堂厍傩粮闹
- 戎智滞痴湍凶偃蔷右于估赵脖铝笆