c#抓取页面,设置POST数组
来源:互联网 发布:淘宝全球购入口 编辑:程序博客网 时间:2024/04/19 13:23
c#抓取页面,设置POST数组
2009-04-18 22:57
//这几天在做一个项目
//把这个拿出来分享一下
using System.IO;
using System.Text;
using System.Data;
using System.Windows;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;//包含必要的库
namespace WindowsApplication1
{
class GetHtml
{
private string source;
private string url;
/// <summary>
///判断输入的是否是一个合法的 URl
/// </summary>
private bool Is_A_URL(string input)
{
return Regex.IsMatch(input, "^http(s)?://"); //这个判断比较简单 ,你可以自己构造正则表达式
}
/// <summary>
/// 提取网页源码的实现代码
/// </summary>
private string GetSource(string webAddress)
{
string str = null;
try
{
Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");
string postData = "stype=" + "2" + "&keywordtype=" + "2" + "&keyword=" + "软件工程" + "&jobarea=" + "0802" + "&fromType=" + "1"; //POST数组赋值
byte[] POST = encoding.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://search.51job.com/jobsearch/keyword_search.php");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = POST.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(POST , 0,POST.Length); //设置POST
newStream.Close();
// 获取结果数据
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default );
str = reader.ReadToEnd();
}
catch (WebException e)
{
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK);
}
return str;
}
public void GetPageSource()
{
if (Is_A_URL(url)) //判断网址是否合法
{
url = url.ToLower();
source = GetSource(url); //获取网页内容
}
else
{
MessageBox.Show("输入的网址不正确,请重新输入!");
}
return;
}
public string seturl
{
set
{
url = value;
}
}
public string getdata
{
get
{
return source ;
}
}
};
}
//把这个拿出来分享一下
using System.IO;
using System.Text;
using System.Data;
using System.Windows;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;//包含必要的库
namespace WindowsApplication1
{
class GetHtml
{
private string source;
private string url;
/// <summary>
///判断输入的是否是一个合法的 URl
/// </summary>
private bool Is_A_URL(string input)
{
return Regex.IsMatch(input, "^http(s)?://"); //这个判断比较简单 ,你可以自己构造正则表达式
}
/// <summary>
/// 提取网页源码的实现代码
/// </summary>
private string GetSource(string webAddress)
{
string str = null;
try
{
Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");
string postData = "stype=" + "2" + "&keywordtype=" + "2" + "&keyword=" + "软件工程" + "&jobarea=" + "0802" + "&fromType=" + "1"; //POST数组赋值
byte[] POST = encoding.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://search.51job.com/jobsearch/keyword_search.php");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = POST.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(POST , 0,POST.Length); //设置POST
newStream.Close();
// 获取结果数据
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default );
str = reader.ReadToEnd();
}
catch (WebException e)
{
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK);
}
return str;
}
public void GetPageSource()
{
if (Is_A_URL(url)) //判断网址是否合法
{
url = url.ToLower();
source = GetSource(url); //获取网页内容
}
else
{
MessageBox.Show("输入的网址不正确,请重新输入!");
}
return;
}
public string seturl
{
set
{
url = value;
}
}
public string getdata
{
get
{
return source ;
}
}
};
}
- c#抓取页面,设置POST数组
- C# POST 方式抓取页面的信息
- 使用C#抓取页面----GET方法,POST方法,抓取登录页面
- POST抓取页面的问题
- C#抓取页面数据汇总
- c#抓取页面乱码解决办法
- C# 抓取页面中的所有链接
- C# Socket同步抓取大页面方法
- 用C#抓取AJAX页面的内容
- C#抓取需要登录的页面
- C#抓取HTML页面(综合)
- C#抓取需要登录的页面
- c#打印页面设置
- c# 抓取网页验证码并post数据
- c# Post/Get提交调用抓取 asp.net
- django 接收页面form的post数组
- C#数组重新设置
- 抓取页面
- 点击按钮时弹出另一个能控制大小的页面,并将某些值通过POST方式传给这个弹出的窗口
- C语言难点专题——数组和指针
- 本博客已搬家
- 无upload组件上传文件
- 20091206微软笔试题目
- c#抓取页面,设置POST数组
- asp.net中一个页面的开启需要启动多少事件?
- Tibco
- 面向对象认识
- asp.net生成静态页 分页显示
- 编程题目003
- ASP.net(c#) 在ACCESS数据库中利用参数使用存储过程例子(防SQL注入)
- dropdownlist绑定的二种方法
- TIbco的SOA