【发布时间】:2017-07-13 01:38:13
【问题描述】:
我一直在做一个小项目,我试图从 HTML 代码中获取 onClick 值。不幸的是,在阅读了一些帖子后,我应该使用 pre_match,但没有奏效。
也许有人可以在这里帮助我并帮助我找到方法?
<div class="results">
<table>
<tbody><tr class="resultName">
<td>1st</td>
<td>2nd</td>
<td>3rd</td>
<td>4th</td>
<td> </td>
</tr>
<tr>
<td>1stText</td>
<td>2ndText</td>
<td>3rdText</td>
<td>4thText</td>
<td><a href="#" onclick="openWin('/link.html','Results',{width:341,height:550}); return false;">Results</a></td>
</tr>
</tbody></table>
</div>
我只能抓取文本内容“结果”。
P.s 找到了一种方法:
$linkcounter = 0;
$links = $dom->getElementsByTagName('a');
foreach ($links as $link){
if ($link->getAttribute('href') == "#" && $link->getAttribute('onclick')){
echo "linkcounter - ".$linkcounter." ".$link->getAttribute('onclick')."</br>";
$linkcounter++;
}
}
【问题讨论】:
标签: php hyperlink onclick html-table href