用Asp.Net c#写的采集小例子
前台页面: <%@ Page language="c#" Codebehind="Gethttpcode.aspx.cs" AutoEventWireup="false" Inherits="coll_net.GetPageHtml" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>采集例子</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="aspNetBuffer" method="post" runat="server"> <div align="center" style="FONT-WEIGHT: bold">得到任意网页源代码</div> <asp:TextBox id="UrlText" runat="server" Width="400px">http://www.0579.info/ </asp:TextBox> <br> <asp:Button id="WebClientButton" Runat="server" Text="用WebClient得到"></asp:Button> <asp:Button id="GetText" style="Z-INDEX: 101; LEFT: 208px; POSITION: absolute; TOP: 72px" runat="server" Text="GetText"></asp:Button> <br> <asp:Button id="WebRequestButton" runat="server" Text="用WebRequest得到"></asp:Button> <br> <asp:TextBox id="ContentHtml" runat="server" Width="100%" Height="360px" TextMode="MultiLine"></asp:TextBox> </form> </body> </HTML> |
后台源代码: using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.IO; using System.Net; using System.Text; using System.Text.RegularExpressions; namespace coll_net { /// <summary> /// GetPageHtml 的摘要说明。 /// </summary> public class GetPageHtml : System.Web.UI.Page { protected System.Web.UI.WebControls.TextBox UrlText; protected System.Web.UI.WebControls.Button WebClientButton; protected System.Web.UI.WebControls.Button WebRequestButton; protected System.Web.UI.WebControls.TextBox ContentHtml; protected System.Web.UI.WebControls.Button GetText; protected System.Web.UI.WebControls.Button Button1; private string PageUrl = ""; private void Page_Load(object sender, System.EventArgs e) private void WebClientButton_Click(object sender, System.EventArgs e) /// 方法二: #region Web 窗体设计器生成的代码 |
以下是引用片段: 这里是针对一些利用 isa server proxy 上网的. 修改下 WebRequest 方法: PageUrl = UrlText.Text; WebRequest request = WebRequest.Create(PageUrl); WebProxy myProxy=new WebProxy(); myProxy = (WebProxy)request.Proxy; myProxy.Address = new Uri("http://代理服务器:端口"); myProxy.Credentials = new NetworkCredential("用户名", "密码", "域名"); request.Proxy = myProxy; WebResponse response = request.GetResponse(); |
以下是引用片段:
另一个实例 〔转〕
private void Page_Load(object sender, System.EventArgs e)
{
string Url = "/blog/upload/20051126115210282.gif";
string StringFileName = Url.Substring(Url.LastIndexOf("/") + 1);
string StringFilePath = Request.PhysicalApplicationPath;
if(!StringFilePath.EndsWith("/")) StringFilePath += "/";
MSXML2.XMLHTTP _xmlhttp = new MSXML2.XMLHTTPClass();
_xmlhttp.open("GET",Url,false,null,null);
_xmlhttp.send("");
if( _xmlhttp.readyState == 4 )
{
if(System.IO.File.Exists(StringFilePath + StringFileName))
System.IO.File.Delete(StringFilePath + StringFileName);
System.IO.FileStream fs = new System.IO.FileStream(StringFilePath + StringFileName, System.IO.FileMode.CreateNew);
System.IO.BinaryWriter w = new System.IO.BinaryWriter(fs);
w.Write((byte[])_xmlhttp.responseBody);
w.Close();
fs.Close();
Response.Write ("文件已经得到。<br><a href=’" + Request.ApplicationPath + StringFileName +"’ target=’_blank’>");
Response.Write ("查看" + StringFileName + "</a>");
}
else
Response.Write (_xmlhttp.statusText);
Response.End();
}
用Asp.Net c#写的采集小例子相关推荐
- asp.net 一个简易权限的小例子设计
asp.net 一个简易权限的小例子设计 近日在阅读一本asp.net的书时(国人写的),其中提到了一个简易权限的小例子,感觉说的还是比较清楚,有点代表性, 故在此简单介绍下其实现原理 其核心是 ...
- loadrunner java脚本_用loadrunner11写java脚本小例子(java Vuser)
1.创建工程testHelloWorld 2.写个经典的HelloWorld类,代码如下: package jd.lt; public class HelloWorld { public String ...
- C语言操作MYSQL小例子
http://blog.csdn.net/small_qch/article/details/8180678 初学使用用C语言操作MYSQL,写了个小例子,帖上来献丢人一下,呵呵. 程序很简单,先连接 ...
- MVVM模式的一个小例子
使用SilverLight.WPF也有很长时间了,但是知道Binding.Command的基本用法,对于原理性的东西,一直没有深究.如果让我自己建一个MVVM模式的项目,感觉还是无从下手,最近写了一个 ...
- 西门子行贿门情报列表,我自己写的一个小软件自动搜集到的。
西门子行贿门消息列表 我自己写的一个小软件自动搜集到的. 其他类型情报也能自动收集. · 编号:1 西门子在华行贿案或涉及权力部门_中华财经 http://invest.8bio.com/ ...
- c++ 小游戏_C/C++编程笔记:C语言写推箱子小游戏,大一学习C语言练手项目
C语言,作为大多数人的第一门编程语言,重要性不言而喻,很多编程习惯,逻辑方式在此时就已经形成了.这个是我在大一学习 C语言 后写的推箱子小游戏,自己的逻辑能力得到了提升,在这里同大家分享这个推箱子小游 ...
- 某程序员为方便老婆工作,写了一些小工具给老婆用!如今老婆要离职,公司老板却要求必须把工具留下!网友:跟他收费!...
请点击上面 一键关注! 最近一个程序员发帖说了这么一件有意思的事: 老婆是一个小公司的hr兼行政,工作繁琐,为了支持老婆工作,这个程序员就写了一些小工具给老婆用,包括工牌生成器.日报格式化工具.年会抽 ...
- 运用vue.js写的表格小demo
2019独角兽企业重金招聘Python工程师标准>>> 最近在学习vue.js,我把工作中项目里面的一个小实例用vue.js重构了下,写成一个小demo,巩固自己所学,并与大家分享, ...
- 在Eclipse中写第一个hibernate小例子
在hibernate自带的文档中,包含了一个很简单的小例子,不过这个小例子是基于ant的,而且说的不是很详细,不利于新手学习.在这里,我将在Eclipse中实现这个例子,并给出详细的实现步骤. ...
最新文章
- Linux网络编程--TCP中的三次握手和四次挥手
- 【错误归纳】E: Sub-process /usr/bin/dpkg returned an error code (1)子进程 已安装 post-installation 脚本 返回了错误号 1
- dbface backbone
- DSP学习 -- Visual Studio 操作
- python 字母顺序计数_计数并说出顺序
- 计算机网络——OSI参考模型和网络的排错
- 多元正太分布条件密度
- php内置web server
- c语言代码格式的简单介绍
- CMPP3.0协议(移动)
- 正则表达式(以校验qq是否合法等为例)
- 天翼去主机linux密码是什么意思,useradmin天翼初始密码 密码都是admin
- PHP获取上周一,获取指定日期的上周日期,上周一
- Unity:Firebase接入Apple登录
- java 数据结构和算法 排序
- MapReduce分片、分区、分组 傻傻分不清
- 【uniapp小程序】request发起请求
- LiveData 的基本使用
- 《MATLAB专刊》——利用向量化编程提升MATLAB代码执行效率
- yolov3网络(DarkNet53)结构详解以及Pytorch代码实现