C#_采集
using System;
using System.Net;
using System.Text;
/// <summary>
/// Collect 的摘要说明
/// </summary>
public class Collect
{
// 获取网页源码
public static string GetHttpPage(string HttpUrl, bool CharSet)
{
WebClient wc = new WebClient();
byte[] PageData = wc.DownloadData(HttpUrl);
string PageHtml;
if(CharSet)
PageHtml = Encoding.Default.GetString(PageData);
else
PageHtml = Encoding.UTF8.GetString(PageData);
return PageHtml;
}
// 截取字符串
public static string GetBody(string Constr, string StartStr, string OverStr, bool IncluL, bool IncluR)
{
string ConstrTemp;
int Start, Over;
ConstrTemp = Constr.ToLower();
StartStr = StartStr.ToLower();
OverStr = OverStr.ToLower();
Start = ConstrTemp.IndexOf(StartStr) + StartStr.Length;
if (IncluL)
{
Start -= StartStr.Length;
}
ConstrTemp = ConstrTemp.Substring(Start);
Over = ConstrTemp.IndexOf(OverStr);
if (IncluR)
{
Over += OverStr.Length;
}
ConstrTemp = ConstrTemp.Substring(0, Over);
return ConstrTemp;
}
}