标签:
using HtmlAgilityPack; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Web; namespace ConsoleApplication4 { /// <summary> /// ///娱乐百度百科 ///风之痕 20150821 /// </summary> class Program { public static void Main(string[] args) { while (true) { Console.WriteLine("欢迎来到TOP小百科,请输入您的问题:"); string key= Console.ReadLine(); ASK(key); } Console.ReadKey(); } private static void ASK(string key) { try { string uri = "http://baike.baidu.com/search/word?word=" + key; HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create(uri); HttpWReq.Timeout = 10000; HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse(); StreamReader sr = new StreamReader(HttpWResp.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8")); HtmlDocument doc = new HtmlDocument(); doc.Load(sr); var kwBox = doc.DocumentNode.SelectSingleNode("//div[@class=‘para‘]"); Console.WriteLine(kwBox.InnerText); Console.WriteLine(""); sr.Close(); sr.Dispose(); HttpWResp.Close(); } catch { Console.WriteLine("抱歉您的问题没有答案"); Console.WriteLine(""); } } } }
标签:
原文地址:http://www.cnblogs.com/nnnnn/p/4747670.html