+ -
当前位置:首页 → 问答吧 → 怎样使用C#获取网页中的keywords和description

怎样使用C#获取网页中的keywords和description

时间:2010-03-05

来源:互联网

怎样使用C#获取网页中的title,keywords和description,WinForm和WebForm均可!

作者: zhangzeguang   发布时间: 2010-03-05

通过正则获取title等
string str = "";
  HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(str);
  HttpWebResponse res = (HttpWebResponse)req.GetResponse();
  StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("gb2312"));
  string content = sr.ReadToEnd();
  Console.WriteLine("{0}", Regex.Match(content, @"<title>([^<>]*)</title>").Groups[1].Value);

作者: wuyq11   发布时间: 2010-03-05

WebRequest oRequest = WebRequest.Create("http://www.taobaonzpd.com/");  
  WebResponse oResponse = oRequest.GetResponse();  
  StreamReader oReader = new StreamReader(oResponse.GetResponseStream(),Encoding.GetEncoding("GB2312"));  
  string html = oReader.ReadToEnd();  
  Match m = Regex.Match(html, "<title>(.*)</title>");  
  if (m.Groups.Count == 2)  
  Console.WriteLine(m.Groups[1].Value);  
  Console.ReadLine();

作者: hnliwh   发布时间: 2011-12-19

具体看:http://blog.csdn.net/hnliwh/article/details/7084150

作者: hnliwh   发布时间: 2011-12-19