现在公司做这个,所以必须得学习**
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;
namespace diytrade
{
class Program
{
static void Main(string[] args)
{
ComMethord.FirstLeve _FirstLeve=new diytrade.ComMethord.FirstLeve() ;
string strHtml = string.Empty;
strHtml = GetSourceHtml(_FirstLeve.FirstLink);
Console.Write(strHtml);
}
private static string GetSourceHtml(string urlstr)
{
//根据 url 读取 源文件
urlstr = "http://www.diytrade.com/directory/china/buy/leads-catalogs.html";
//WebRequest wreq = WebRequest.Create(urlstr);
//WebResponse wres = wreq.GetResponse();
//Stream rece = wres.GetResponseStream();
//Byte[] read = new Byte[512];
//int bytes = rece.Read(read, 0, 512);
//string reshtml = "";
//while (bytes > 0)
//{
// Encoding encode = Encoding.GetEncoding("gb2312");
// reshtml += encode.GetString(read, 0, bytes);
// bytes = rece.Read(read, 0, 512);
//}
//return reshtml;
System.Net.HttpWebRequest _Request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(urlstr);
System.Net.HttpWebResponse _Response = (System.Net.HttpWebResponse)_Request.GetResponse();
System.IO.StreamReader _StreamReader = new System.IO.StreamReader(_Response.GetResponseStream(), Encoding.Default);
StringBuilder _StreamString = new StringBuilder();
_StreamString.Append(_StreamReader.ReadToEnd());
_StreamReader.Close();
return _StreamString.ToString();
}
}
}//提取源文件中的文章内容,去掉页面的头尾。