namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string requestUrl = "http://www.most.gov.cn/tztg/201605/t20160503_125403.htm";
HttpWebRequest myReqeust = WebRequest.Create(requestUrl) as HttpWebRequest;
myReqeust.Timeout = 1000 * 5; //1秒 = 1000毫秒
myReqeust.Method = "GET";
HttpWebResponse myResponse = myReqeust.GetResponse() as HttpWebResponse;
HttpWebResponse response = (HttpWebResponse)myReqeust.GetResponse();
Encoding htmlEncoding = Encoding.GetEncoding("GBK");
using (StreamReader reader = new StreamReader(myResponse.GetResponseStream(), htmlEncoding))
{
string html = reader.ReadToEnd();
}
}
public void Main(string[] myReqeust)
{
Program programl = new Program();
int i = Program.main(myReqeust);
var text = File.ReadAllText("TextFile1.txt");
var doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(text);
var xpath = "//title[@*]";
var books= doc.DocumentNode.SelectNodes(xpath);
foreach (var book in books)
{
Console.WriteLine(book.OuterHtml);
}
}
}
}
相关分类