c#采集网页用得几个函数 有解释
2008-12-07 16:27
295 查看
当当全新正版图书,9周年店庆,特价销售,全场免运费!
public string GetHtmlSource(string Url, string charset) //得到Html源代码
{
if (charset == "" || charset == null) charset = "gb2312";
string text1 = "";
try
{
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(Url);
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
Stream stream1 = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(stream1, Encoding.GetEncoding(charset));
text1 = reader1.ReadToEnd();
stream1.Close();
response1.Close();
}
catch (Exception exception1)
{
}
return text1;
}
//获得页面HTML代码中开始标记和结束标记中间的数据:测试可用
//参 数:HTML源代码 ,开始标记,结束标记
public string SniffwebCode(string code, string wordsBegin, string wordsEnd)
{
string NewsTitle = "";
Regex regex1 = new Regex("" + wordsBegin + @"(?<title>[/s/S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
{
NewsTitle = match1.Groups["title"].ToString();
}
return NewsTitle;
}
public ArrayList SniffwebCodeReturnList(string code, string wordsBegin, string wordsEnd)
{
ArrayList urlList = new ArrayList();
//string NewsTitle = "";
Regex regex1 = new Regex("" + wordsBegin + @"(?<title>[/s/S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
{
urlList.Add(match1.Groups["title"].ToString());
}
return urlList;
}
public string GetHtmlSource(string Url, string charset) //得到Html源代码
{
if (charset == "" || charset == null) charset = "gb2312";
string text1 = "";
try
{
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(Url);
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
Stream stream1 = response1.GetResponseStream();
StreamReader reader1 = new StreamReader(stream1, Encoding.GetEncoding(charset));
text1 = reader1.ReadToEnd();
stream1.Close();
response1.Close();
}
catch (Exception exception1)
{
}
return text1;
}
//获得页面HTML代码中开始标记和结束标记中间的数据:测试可用
//参 数:HTML源代码 ,开始标记,结束标记
public string SniffwebCode(string code, string wordsBegin, string wordsEnd)
{
string NewsTitle = "";
Regex regex1 = new Regex("" + wordsBegin + @"(?<title>[/s/S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
{
NewsTitle = match1.Groups["title"].ToString();
}
return NewsTitle;
}
public ArrayList SniffwebCodeReturnList(string code, string wordsBegin, string wordsEnd)
{
ArrayList urlList = new ArrayList();
//string NewsTitle = "";
Regex regex1 = new Regex("" + wordsBegin + @"(?<title>[/s/S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
{
urlList.Add(match1.Groups["title"].ToString());
}
return urlList;
}
相关文章推荐
- c#采集网页用得几个函数 有解释
- c#采集网页用得几个函数
- c#采集网页用得几个函数
- C# 时间函数(几个常用时间,程序运行计时,页面运行计时)
- C#网页数据采集(一)HtmlAgilityPack
- C#操作Excel的几个函数
- C#实现网页抓取函数
- C#网页数据采集(三)HttpWebRequest
- C# 网页信息采集(数据访问)
- [C#]一个简单的获取网页源代码的函数
- ASP采集入库生成本地文件的几个函数
- asp.net(c#)做一个网页数据采集工具
- C# 网页图片采集
- 浅析基于ASP.NET网页的C#数据采集
- C# WEB网页内容采集
- C#操作Excel的几个函数
- C# 网页信息采集(Form.cs)
- 网络采集软件核心技术剖析系列(4)---使用C#语言如何将html网页转换成pdf(html2pdf)
- OpenGL入门8——几个重要函数解释
- C# 网页信息采集(数据访问)