我为类似于Youtube的视频托管网站上的某个视频生成了一些视频嵌入代码。我需要提取到视频源的直接链接(* .m4v)。对于下面的这个例子,我想提取值“http://play.op.ac.nz/images/media/beb431bc59587dc71e10939d214e9515_1315897772.m4v”并将其放在一个字符串中:
<script type="text/javascript" src="http://play.op.ac.nz/js/embed.js.php?key=beb431bc59587dc71e10939d214e9515"></script>
<noscript>
<!-- Version SVN: $Id: _playerVideo.php 19008 2011-05-17 19:06:32Z sven $ -->
<div id="flash">
<div id="flashcontent">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="flvplayer_4e71fa175218d" name="c6a80378-3eb2-47e7-8415-ba1f7cff037e" width="720" height="406" style="position:relative;top:0;left:0;z-index:9999;">
<param name="movie" value="http://play.op.ac.nz/flash/vimp.swf" />
<param name="flashvars" value="hosturl=http%3A%2F%2Fplay.op.ac.nz%2Fmedia%2Fflashcomm&mediaid=195&context=embeded&skin=http%3A%2F%2Fplay.op.ac.nz%2Fflash%2Fskins%2Fice_white.swf&autohidesidebaronplay=true" />
<param name="scale" value="true" />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="wmode" value="opaque" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="http://play.op.ac.nz/flash/vimp.swf" width="720" height="406" wmode="opaque">
<param name="flashvars" value="hosturl=http%3A%2F%2Fplay.op.ac.nz%2Fmedia%2Fflashcomm&mediaid=195&context=embeded&skin=http%3A%2F%2Fplay.op.ac.nz%2Fflash%2Fskins%2Fice_white.swf&autohidesidebaronplay=true" />
<param name="scale" value="true" />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="wmode" value="opaque" />
<!--<![endif]-->
<div class="leanback-player-video">
<video id="index_video" width="720" height="406" preload="metadata" controls="" poster="http://play.op.ac.nz/cache/99590fa59570e38b09e63000c99a6859.jpg">
<source src="http://play.op.ac.nz/images/media/beb431bc59587dc71e10939d214e9515_1315897772.m4v" type="video/mp4" />
<source src="http://play.op.ac.nz/images/media/beb431bc59587dc71e10939d214e9515_1315897772.webm" type="video/webm" />
<source src="http://play.op.ac.nz/images/media/beb431bc59587dc71e10939d214e9515_1315897772.ogv" type="video/ogg" />
<p style="margin: 15px;">
Hint: Unfortunately your browser does not have Flash Player installed or the Flash Player version is outdated. You need Flash Player to view media in this community. <a href="http://www.macromedia.com/go/getflashplayer">Download Flash Player</a>
</p>
<img alt="How to safely operate a power actuated nail gun" title="How to safely operate a power actuated nail gun" src="http://play.op.ac.nz/cache/99590fa59570e38b09e63000c99a6859.jpg" />
</video>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>
</div>
</noscript>
我已经完成了搜索并在PHP和Python中找到了大量的解决方案,但我无法解读。我有一段时间没有接触过C#,所以任何帮助都会受到赞赏。
答案 0 :(得分:2)
最好的方法是使用HTML Agility Pack。将HTML解析为字符串,在字符串中搜索第一次出现的
'<source src="'
并终止于
'"'.
把你的发现并把它放到你的变量中。
以下是一个带有示例的网址:http://olussier.net/2010/03/30/easily-parse-html-documents-in-csharp/