[英]DOMXPath query error , not working in web server
i am using the following code to grab some data from a site and store them in a database . 我正在使用以下代码从站点中获取一些数据并将其存储在数据库中。
<?php
error_reporting(0);
include("database.php");
$dom = new DOMDocument();
$url = "http://www.kitco.com";
$html = file_get_contents($url);
$dom->loadHTML($html);
$xp = new DOMXPath($dom);
get_live_spot_gold();
get_silver_and_pgm();
function get_live_spot_gold()
{
global $xp;
$live_spot_gold = array();
$bid='000';
$change='000';
$qs = $xp->query('//div[@class="item_border"]/table/tr[@class="alternating"][1]/td[2]');
foreach($qs as $q)
{
$bid = $q->textContent;
break;
}
$qs = $xp->query('//div[@class="item_border"]/table/tr[@class="alternating"][2]/td[2]');
foreach($qs as $q)
{
$change = $q->textContent;
break;
}
//insert into db
echo $bid."<br>";
echo $change."<br>";
$query = "UPDATE live_spot_gold SET _bid = '$bid' , _change = '$change'";
echo $query;
$result = mysql_query($query);
if(!$result)echo "problem in live spot gold"."<br>";
}
function get_silver_and_pgm()
{
global $xp;
$silver_and_pgm = array();
$cnt=0;
$qs = $xp->query('//td[@id="right_column"]/div[@class="item_container"][2]/div[@class="item_border"]/table/tr');
foreach ($qs as $q)
{
$line = $q->nodeValue;
$demo="";
for($i=0;$i<strlen($line);$i++)
{
if($line[$i]==' ')
{
$demo.=' ';
for( ;$line[$i]==' ';$i++);
}
$demo.=$line[$i];
}
$words = explode(" ",$demo);
$silver_and_pgm[$cnt][0]=$words[0]; //metal name
$silver_and_pgm[$cnt][1]=$words[1]; //bid
$silver_and_pgm[$cnt][2]=$words[2]; //change
$cnt++;
}
for($i=0;$i<$cnt;$i++)
{
$metal_name = $silver_and_pgm[$i][0];
$bid = $silver_and_pgm[$i][1];
$change = $silver_and_pgm[$i][2];
//echo "here";
echo $metal_name."<br>";
echo $bid."<br>";
echo $change."<br>";
//$query = "insert into 'silver_and_pgm' values('$metal_name','$bid','$change')";
//$query = "UPDATE silver_and_pgm set _bid='$bid' WHERE _metal_name='$metal_name'";
//$query = "UPDATE silver_and_pgm set _bid = '$bid' WHERE _metal_name = '$metal_name'";
$query = "UPDATE silver_and_pgm set _bid='$bid',_change = '$change' WHERE _metal_name
like'$metal_name%'";
echo $query."<br>";
$result = mysql_query($query);
if(!$result)
echo "problem in silver_and_pgm"."<br>";
}
}
?>
its just working fine in my localhost . 它只是在我的本地主机工作正常。 but not in my web server . 但不在我的Web服务器中。 Its grabbing data and storing them in localhost ... no query , no echo statement is working in web server. 它获取数据并将其存储在localhost中...在Web服务器中没有查询,没有echo语句。 would anybody please suggest a way to handle this problem ?? 有人请提出一种解决这个问题的方法吗?
DOM requires PHP 5 (and libxml to be installed). DOM需要PHP 5(和libxml要安装)。 Make sure your server meets the requirements by running php_info(). 通过运行php_info()确保服务器满足要求。 Also, turn back on your error reporting and see what errors you get. 另外,重新打开错误报告并查看得到的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.