免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

C#從新浪新聞上提取新聞標(biāo)題

 下面我以新浪軍事新聞模塊提取軍事新聞的標(biāo)題,將提取到的新聞標(biāo)題保存到記事本上

鄒平ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18982081108(備注:SSL證書合作)期待與您的合作!

 

  1. static void Main(string[] args) 
  2.       { 
  3.           Stopwatch watch = new Stopwatch(); 
  4.           watch.Start(); 
  5.           WebClient wc = new WebClient(); 
  6.           int count = 0; 
  7.           //正則表達(dá)式 
  8.           string regLinks = "<li><a\\s+href=\"http://mil.news.sina.com.cn/20\\d{2}-\\d{2}-\\d{2}/\\d{10}\\.html\"\\s+target=\"_blank\">(.+?)</a><span\\s+class=\"time\">(.+?)</span></li>"; 
  9.           //由于耗時(shí)太久,在這里我只提取新浪100個(gè)頁面的新聞標(biāo)題 
  10.           for (int i = 1; i < 100; i++) 
  11.           { 
  12.               //http://roll.mil.news.sina.com.cn/col/zgjq/index_4.shtml 
  13.               string url = @"http://roll.mil.news.sina.com.cn/col/zgjq/index_"+i+".shtml"; 
  14.  
  15.               string html = wc.DownloadString(url); 
  16.               MatchCollection matchs = Regex.Matches(html, regLinks); 
  17.               using (StreamWriter sw = new StreamWriter(@"c:\news.txt", true, Encoding.GetEncoding("gb2312"))) 
  18.               { 
  19.                   foreach (Match match in matchs) 
  20.                   { 
  21.                       if (match.Success) 
  22.                       { 
  23.                           sw.WriteLine(match.Groups[1].Value + "\t" + match.Groups[2].Value); 
  24.                           count++; 
  25.                       } 
  26.                   } 
  27.               } 
  28.           } 
  29.           watch.Stop(); 
  30.           Console.WriteLine("共提取了{(lán)0}個(gè)新聞標(biāo)題",count); 
  31.           Console.WriteLine("共計(jì)用時(shí):{0}",watch.Elapsed); 
  32.           Console.ReadKey(); 
  33.       } 

朋友們可以提取其他相關(guān)網(wǎng)站的新聞標(biāo)題,但是提取的時(shí)候一定要記得找源代碼規(guī)律,因?yàn)?/p>

  1. //正則表達(dá)式 
  2. string regLinks = "<li><a\\s+href=\"http://mil.news.sina.com.cn/20\\d{2}-\\d{2}-\\d{2}/\\d{10}\\.html\"\\s+target=\"_blank\">(.+?)</a><span\\s+class=\"time\">(.+?)</span></li>"; 

正則表達(dá)式的拼接是根據(jù)標(biāo)題源代碼的規(guī)律來提取的,如果不找規(guī)律,是很難進(jìn)行提取的。

希望大家可以根據(jù)程序來提取其他網(wǎng)站的內(nèi)容

當(dāng)前題目:C#從新浪新聞上提取新聞標(biāo)題
當(dāng)前鏈接:http://m.newbst.com/article26/jeshjg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號網(wǎng)站建設(shè)ChatGPT自適應(yīng)網(wǎng)站搜索引擎優(yōu)化網(wǎng)站設(shè)計(jì)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)