我对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>
我对这个部分感兴趣:
1g2595卢比
获取simple_dom_html.php文件并将其包含在内。
$html = str_get_html($buffer);
$html->find('any class etc');