当前位置: 代码迷 >> C# >> C#如何写正则得到小弟我想要的数据
  详细解决方案

C#如何写正则得到小弟我想要的数据

热度:227   发布时间:2016-05-05 02:56:49.0
C#怎么写正则得到我想要的数据
下面是我从豆瓣api请求回来的一张页面数据。我想获取里面所有的: /movie/subject/id号/。求大神讲解。就是这种数据:/movie/subject/3326764/    。           是不是用 Regex.Split()方法。怎么写呢


<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
        <meta http-equiv="Cache-Control" content="no-cache" />
        <meta http-equiv="Pragma" content="no-cache" />
        <meta http-equiv="Expires" content="-1" />
        <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, maximum-scale=1.0, user-scalable=1" />
        <meta name="format-detection" content="telephone=no" />
        <link rel="shortcut icon" href="http://img3.douban.com/f/mearas/74a1b58c6fd21def48f0b4cf6787285463425263/mobiledouban/public/static/favicon.ico" type="image/x-icon" />
        <title>
    电影标签:日本 - 豆瓣电影
</title>
        <link rel="stylesheet" type="text/css" href="http://img3.douban.com/f/mearas/f290c79e966b6dd99e835b1f70b5e400dbd12ef4/mobiledouban/public/static/css/assets/core.css" />
        <meta name="apple-itunes-app" content="app-id=907002334, app-argument=">
        
    <link rel="apple-touch-icon" href="http://img3.douban.com/f/mearas/ad8b103f91563979edc2c135b5968419713b76e4/mobiledouban/public/static/images/movie/movie_icon.png" />

        
    <link rel="stylesheet" type="text/css" href="http://img3.douban.com/f/mearas/7db13b04c6b11fda242da25f787d7b9bb600c5fb/mobiledouban/public/static/css/movie/wap.css" />

        <style type="text/css">
            
        </style>
    </head>

    <body>
        <div class="wrapper">
            <div id="hd">
                
<a href="/movie/recent/">
    <img src="http://img3.douban.com/f/mearas/4e8963624687a0c6a818da35addfb07d2afcb106/mobiledouban/public/static/images/movie/movie_mobile_v2.gif"  alt="豆瓣电影" width="70" height="17" />
</a>

            </div>

            <div id="bd">
                

<div class="nav">
        




     <a href="/movie/recent/">热映中</a>

<b>|</b>


     <a href="/movie/tag/">标签</a>

<b>|</b>


     <a href="/movie/top250/">Top250</a>

<b>|</b>


     <a href="/movie/people/">我看</a>



</div>


    
        
        
        <form action="/movie/search/tag_search" method="get">
        <div class="srh">
        <input type="text" class="srh-text" name="q" value="日本">
        <input name="tag" type="submit" value="搜标签" />
        </div>
        </form>



    
    <div class="movie-items list">
            <div class="item">
                <p>
        <span ><a href="/movie/subject/3240828/">15名动画人</a></span>
        <span class="rating">8.7</span>
</p>
                <p>
                    
    
        <div class="itm">
                    2007 / 
                    动画 短片 / 
                    1分钟 / 
                    22805人看过
        </div>

                </p>
            </div>
            <div class="item">
                <p>
        <span ><a href="/movie/subject/1299607/">东京日和</a></span>
        <span class="rating">8.4</span>
</p>
                <p>
                    
    
        <div class="itm">
                    1997 / 
                    剧情 / 
                    121分钟 / 
                    14858人看过
        </div>

                </p>
            </div>
            <div class="item">
                <p>
        <span ><a href="/movie/subject/24858414/">白雪公主杀人事件</a></span>
        <span class="rating">7.5</span>
</p>
                <p>
                    
    
        <div class="itm">
                    2014 / 
                    剧情 悬疑 / 
                    126分钟 / 
                    34900人看过
        </div>

                </p>
            </div>
            <div class="item">
                <p>
        <span ><a href="/movie/subject/4848701/">日常</a></span>
        <span class="rating">9.1</span>
</p>
                <p>
                    
    
        <div class="itm">
                    2011 / 
                    动画 / 
                    25分钟 / 
                    12742人看过
        </div>

                </p>
            </div>
            <div class="item">
                <p>
        <span ><a href="/movie/subject/1457573/">新世纪福音战士</a></span>
        <span class="rating">9.3</span>
</p>
                <p>
                    
    
        <div class="itm">
                    1995 / 
                    动画 动作 剧情 科幻 惊悚 / 
                    26分钟 / 
                    55350人看过
        </div>

                </p>
            </div>
            <div class="item">
                <p>
        <span ><a href="/movie/subject/10001418/">冰菓</a></span>
        <span class="rating">8.6</span>
</p>
                <p>
                    
    
        <div class="itm">
                    2012 / 
                    动画 悬疑 / 
                    26分钟 / 
                    15945人看过
        </div>

                </p>
            </div>
            <div class="item">
                <p>
        <span ><a href="/movie/subject/25777784/">再见歌舞伎町</a></span>
        <span class="rating">7.4</span>
</p>
                <p>
                    
    
        <div class="itm">
                    2014 / 
                    剧情 爱情 / 
                    134分钟 / 
                    2716人看过
        </div>

                </p>
            </div>
            <div class="item">
                <p>
        <span ><a href="/movie/subject/20491392/">银之匙</a></span>
        <span class="rating">9.1</span>
</p>
                <p>
                    
    
        <div class="itm">
                    2013 / 
                    剧情 喜剧 动画 / 
                    23分钟 / 
                    9720人看过
        </div>

                </p>
            </div>
            <div class="item">
                <p>
        <span ><a href="/movie/subject/1394510/">十二国记</a></span>
        <span class="rating">9.0</span>
</p>
                <p>
                    
    
        <div class="itm">
                    2002 / 
                    动画 冒险 剧情 奇幻 / 
                    25分钟 / 
                    25426人看过
        </div>

                </p>
            </div>
            <div class="item">
                <p>
        <span ><a href="/movie/subject/3326764/">永生之酒</a></span>
        <span class="rating">9.0</span>
</p>
                <p>
                    
    
        <div class="itm">
                    2007 / 
                    动画 动作 冒险 喜剧 犯罪 奇幻 恐怖 惊悚 / 
                    13579人看过
        </div>

                </p>
            </div>
        
            <div class="item">

<div class="paginator">
        <a href="/movie/tag/movies?tag=%E6%97%A5%E6%9C%AC&amp;page=17">下一页</a><b>|</b>
        <a href="/movie/tag/movies?tag=%E6%97%A5%E6%9C%AC&amp;page=15">上一页</a><b>|</b>
        <a href="/movie/tag/movies?tag=%E6%97%A5%E6%9C%AC&amp;page=200">最后页</a><b>|</b>
        <a href="/movie/tag/movies?tag=%E6%97%A5%E6%9C%AC&amp;page=1">第一页</a><b>|</b>
    <span> 16/200 </span>
</div>
</div>
    </div>
    <div class="list"> 
        <div class="top-item"><a href="/movie/tag/">浏览热门标签</a></div>
    </div>


    
        
        
        <form action="/movie/search/tag_search" method="get">
        <div class="srh">
        <input type="text" class="srh-text" name="q" value="日本">
        <input name="tag" type="submit" value="搜标签" />
        </div>
        </form>

            </div>

            <div id="ft">
                

<div>
<a href="#hd">回顶部</a>
 | <a href="/feedbacks/new">反馈</a>
 | <a href="http://www.douban.com/doubanapp/app?channel=Douban_mobileAD&direct_dl=1">下载豆瓣App</a>
   <img src="http://img3.douban.com/f/mearas/71a3d0661dce65b7f685dd5fb9421476d0728eab/mobiledouban/public/static/images/movie/new_menu_top.gif"  alt="new"/>
</div>

<a href="/">首页</a> &#183; 
<a href="/group/">小组</a> &#183;
<a href="/book_search">读书</a> &#183; 
<a href="/movie/recent/">电影</a> &#183;
<a href="/fm/download">豆瓣FM</a> &nbsp;|
<a href="/back_douban">普通版</a>

<div class="date">
[09-12 22:57]
</div>

<div class="copyright">
    &#169; 2015 豆瓣
</div>


           
<div class="promotion-ad">
    <a class="promotion-ad-wrapper" href="" target="_blank">
        <table class="ad promotion-ad-app">
            <tbody>
                <tr>
                    <td>
                        <img class="promotion-ad-icon" src="" alt="App" />
                    </td>
                    <td>
                        <span class="promotion-ad-slogan"></span>
                    </td>
                    <td>
                        <a class="promotion-ad-button" href="">立即下载</a>
                    </td>
                </tr>
            </tbody>
        </table>
    </a>
</div>
<style>
.promotion-ad { position:fixed; bottom: 0; left: 0; right: 0; display: none; }
.promotion-add-wrapper { display: block; }
.promotion-ad-app { width:100%; background: #363636; padding: 8px 0 0 0; border-spacing: 0px; border-collapse: separate; }
.promotion-ad-close { width: 20px; height: 20px; border-radius: 20px; text-align: center; line-height: 20px; position: absolute; top: -10px; left: 0; font-size: 26px; background: #1f1f1f; }
.promotion-ad td { vertical-align: middle; }
.promotion-ad img { margin-left: 10px; height: 35px;}
.promotion-ad span { color: #fff; display: inline-block; margin-left: 5px }
.promotion-ad-button { display: inline-block; padding: .3em .8em; border-radius: 3px; margin-top: -8px; }
#promotion-ad-moment .promotion-ad-close { color: #eda05c; }
#promotion-ad-moment .promotion-ad-button { background: #eda05c; color: #fff; }
#promotion-ad-dongxi .promotion-ad-close { color: #de533c; }
#promotion-ad-dongxi .promotion-ad-button { background: #fff; color: #de533c; }
#promotion-ad-fm .promotion-ad-button { background: #EBD9A8; color: #fff; }
</style>
    </body>
</html>



------解决思路----------------------
Regex.Matches(html,@"/movie/subject/(\d+)")

match.Group[1].Value就是id值
  相关解决方案