我对 PHP 很陌生,它不是我的域,但是现在我需要从网站中提取某个值,我在互联网上查找并找到了我根据需要实现的以下功能:
<?php
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'http://www.indiagoldrate.com/gold-rate-in-mumbai-today.htm');
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if (empty($buffer))
{
print "Sorry, example.com are a bunch of poopy-heads.<p>";
}
else
{
print $buffer;
}
?>
到目前为止,我可以检索整个页面,但我只对所述页面中的一个值感兴趣,我需要如何做的想法?
我需要的网页代码:(简单查看源码)
<tr>
<td>MUMBAI<BR>Thu, Jul 25th, 2013</td>
<td><TABLE class="innerTable">
<TR>
<TD>1g </TD>
<TD>Rs. 2,595</TD>
</TR>
<TR>
<TD>8g</TD>
<TD>Rs. 20,760</TD>
</TR>
<TR>
<TD>10g</TD>
<TD>Rs. 25,950</TD>
</TR>
<TR>
<TD>100g</TD>
<TD>Rs. 2,59,500</TD>
</TR>
<TR>
<TD>1 KG</TD>
<TD>Rs. 25,95,000</TD>
</TR>
</TABLE></td>
<td><TABLE class="innerTable">
<TR>
<TD>1g </TD>
<TD>Rs. 2,795</TD>
</TR>
<TR>
<TD>8g</TD>
<TD>Rs. 22,360</TD>
</TR>
<TR>
<TD>10g</TD>
<TD>Rs. 27,950</TD>
</TR>
<TR>
<TD>100g</TD>
<TD>Rs. 2,79,500</TD>
</TR>
<TR>
<TD>1 KG</TD>
<TD>Rs. 27,95,000</TD>
</TR>
</TABLE></td>
我对这部分感兴趣:
1克卢比。2,595