我想读取一个网页的一些数据,网址是:http://www.xjflcp.com/servlet/sscflash?type=full&rand=2266
我的代码是这样的:
$url="http://www.xjflcp.com/servlet/sscflash?type=full&rand=2266";
$doc = new DOMDocument();
$doc->load($url); //读取xml文件
// $datas= $doc->saveXML();
// $lst = $doc->getElementsByTagName('history1');
// $t1 = $lst->item(0)->getElementsByTagName("draw")->item(0)->nodeValue; //取得name的标签的对象数组
// $t1 = substr($t1,2,6)."0".substr($t1,-2);
// $t2 = $lst->item(0)->getElementsByTagName("prize_number")->item(0)->nodeValue; //取得name的标签的对象数组
// $t2 = str_replace("|",",",$t2);
$lst = $doc->getElementsByTagName('row');
// for ($i=0; $i<$lst->length; $i++) {
for ($i=0; $i<2; $i++) {
$iframe= $lst->item($i);
$t1=$iframe->attributes->getNamedItem('draw')->value;
$t2=$iframe->attributes->getNamedItem('prize_number')->value;
想获取第二行
<recent_draw>
<draw>2014082856</draw>
<prize_number>1|4|0|9|5</prize_number>
<sale_count>57446</sale_count>
<prize_levels>23</prize_levels>>
draw、prize_number请问应该怎么改
------解决方案--------------------
$url="http://www.xjflcp.com/servlet/sscflash?type=full&rand=2266";
$doc = new DOMDocument();
$doc->load($url);
$recent_draws=$doc->getElementsByTagName("recent_draw");
$recent_draw=$recent_draws->item(0);
$draw=getNodeVal($recent_draw,"draw");
$prize_number=getNodeVal($recent_draw,"prize_number");
echo $draw.'<br>';
echo $prize_number.'<br>';
function getNodeVal(&$myNode,$tagName){
return $myNode->getElementsByTagName($tagName)->item(0)->nodeValue;
}
/*
2014082865
4
------解决方案--------------------
6
------解决方案--------------------
9
------解决方案--------------------
6
------解决方案--------------------
4
*/
友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群