【发布时间】:2014-02-08 10:55:35
【问题描述】:
<!-- This Div repeated in HTML with different properties value -->
<div style="position:absolute; overflow:hidden; left:220px; top:785px; width:347px; height:18px; z-index:36">
<!-- Only Unique Thing is This in few pages -->
<a href="http://link.domain.com/?id=123" target="_parent">
<!-- OR in some pages Only Unique Thing is This, ending with mp3 extension -->
<a href="http://domain.com/song-title.mp3" target="_parent">
<!-- This Div also repeated multiple in HTML -->
<FONT style="font-size:10pt" color=#000000 face="Tahoma">
<DIV><B>Harjaiyaan</B> - Nandini Srikar</DIV>
</FONT>
</a>
</DIV>
我们有非常脏的 html 标记,它是由某些程序或应用程序生成的。我们想从这段代码中提取“Urls”以及“Text”。
在href 中,我们使用两种类型的 url,Url 1 模式:'http://link.domain.com/id=123',Url 2 模式:'http://domain.com/sons-title.mp3'
在第一场比赛中,我们是特定的模式,但在第二个 url 中,我们没有模式只是以 '.mp3' 扩展名结尾的 url。
是否有一些函数可以从这个模式和文本代码中提取url?
注意: 没有 DOM,有什么方法可以匹配一个 href 和 text 之间的正则表达式?预匹配?
【问题讨论】:
-
没有什么神奇的功能可以为您完成所有工作。你必须编写代码来做你想做的事。使用诸如 DOMDocument 之类的 DOM 解析器来完成此操作。