0
我正在研究音乐下载程序,并且必须阅读网站的整个网页,然后需要显示结果。所以我读了整个网络的源代码。现在,歌曲名称和该URL可以是如下面的HTML页面:在匹配模式中遇到问题
HTML代码:
<div id="right_song">
<div style="font-size:15px;"><b>Name of song</b></div>
<div style="clear:both;"></div>
<div style="float:left;">
<div style="float:left; height:27px; font-size:13px; padding-top:2px;">
<div style="float:left;"><a href="link of song" rel="nofollow" target="_blank" style="color:green;">Download</a>
所以我想到了用这种模式,然后匹配它得到的名称和网址。
我做了如下模式:
<div id=\"right_song\">
<div style=\"font-size:15px;\"><b>([^<]*)</b></div>
<div style=\"clear:both;\"></div>
<div style=\"float:left;\">
<div style=\"float:left; height:27px; font-size:13px; padding-top:2px;\">
<div style=\"float:left;\"><a href=\"([^\"]*)\" rel=\"nofollow\" target=\"_blank\" style=\"color:green;\">Download</a>
但它总是返回作为没有找到这样模式在那里,我错了。
请指导我使它完美。
我当然不会尝试在如此大量的数据上使用正则表达式。使用HTML解析器,而不是正则表达式。您正在使用错误的工具进行这项工作 - 比如在使用螺丝刀时使用剃刀刀片。 –
@Jonathon Reinhart我正在阅读整个网页,然后检查找到模式来获取歌曲。因为我想为应用程序的不同布局将html解析器提供给我不同的应用程序的视图? –