【发布时间】:2012-01-07 01:40:59
【问题描述】:
我想从网站上的图像中检索 alt。过去,我是这样做的:
@$doc=new DOMDocument();
@$doc->loadHTML($html); //$html is the website
$xml=simplexml_import_dom($doc); // just to make xpath more simple
$images=$xml->xpath('//img');
foreach ($images as $img) {
echo $img['alt'];
}
但现在我想要的图像在 div style="padding: 15px 0px 15px 25px;"
我将如何检索图像? 我试图将 $xml->xpath() 更改为其他内容,但没有成功。
如果有人知道我需要做什么,将不胜感激。
谢谢!
我的错,这实际上是包含数据的地方。
<div class="numbers">
<table cellpadding="3">
<tbody>
<tr>
<tr>
<td>
<img alt="12" src="/images/new/date/date5.gif">
<img alt="39" src="/images/new/date/date4.gif">
<img alt="32" src="/images/new/date/date3..gif">
<img alt="4" src="/images/new/date/date2.gif">
<img alt="20" src="/images/new/date/date1.gif">
</td>
<td>
</tr>
</tbody>
</table>
</div>
【问题讨论】:
-
图像是否有任何显着特征,例如类或 id?你知道它的路径吗?你能显示 HTML 吗?
-
只是出于好奇,为什么需要 alt?为了什么?
-
@deceze 我已经提供了它们图像的新位置...你知道我将如何检索它们吗?
-
@Gabriel Santos 我需要图像 alt 中的数据