头大啊,一个(-)符号搞得人要跪了,求大神帮下

a8849516 2017-06-06 12:13:03

接口发来的数据是没带(-)的,我这只能采集带(-)的,有什么办法能解决啊。

接口商提供的PHP演示能显示成这样,可是又没法采集


<?php header("Content-type: text/html; charset=utf-8"); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<meta http-equiv="refresh" content="5">
</head>
<body>
<?php
echo '<br>';
$src = 'http://f.apiplus.cn/cqssc.xml';
echo '<br>采集地址:'.$src.'<br>';
$src .= '?_='.time();
$xml = file_get_contents(urldecode($src));
$xml = simplexml_load_string($xml);

echo "<br>".date('Y-m-d H:i:s')."共采集到{$xml->attributes()->rows}行开奖数据:<br>";
for ($i = 0; $i < count($xml->row); $i++) {
$p = $xml ->row[$i]->attributes()->expect;
echo '<br>开奖期号:'.substr($p,0,8).'-'.substr($p,-3,3);
echo '<br>开奖号码:'.$xml ->row[$i]->attributes()->opencode;
echo '<br>开奖时间:'.$xml ->row[$i]->attributes()->opentime;
echo '<br>';
}
?>
</body>
</html>
...全文
674 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2017-06-06
  • 打赏
  • 举报
回复
他原来就那样,你得自己处理一下
$src = 'http://f.apiplus.cn/cqssc.xml';
$xml = file_get_contents(urldecode($src));
$xml = simplexml_load_string($xml);
foreach($xml->row as $r) {
  foreach($r->attributes() as $k=>$v) {
    if($k == "expect") $v = join("-", str_split($v, 8));
    echo "$k => $v\n";
  }
}

expect => 20170606-040
opencode => 9,6,8,6,0
opentime => 2017-06-06 12:40:40
expect => 20170606-039
opencode => 3,5,7,8,1
opentime => 2017-06-06 12:30:40
expect => 20170606-038
opencode => 6,8,6,7,3
opentime => 2017-06-06 12:20:40
expect => 20170606-037
opencode => 5,9,8,2,4
opentime => 2017-06-06 12:10:40
expect => 20170606-036
opencode => 8,9,3,4,4
opentime => 2017-06-06 12:00:40
a8849516 2017-06-06
  • 打赏
  • 举报
回复

大神来帮帮啊,解决了给红包啊
a8849516 2017-06-06
  • 打赏
  • 举报
回复
2170605-062 这里面这个(-) 我用的接口是显示2170605062 采集的内容少了一个(-),导致出问题
xuzuning 2017-06-06
  • 打赏
  • 举报
回复
什么意思? 那个 - 是 XML 浏览工具附加的,用于折叠显示 XML 文档
a8849516 2017-06-06
  • 打赏
  • 举报
回复
function createTimeProcess(ht,mt,st){ ht=ht||23; mt=mt||59; st=st||59; var timeTmp='',result=[]; for(var h=0;h<=ht;h++) for(var m=0;m<=mt;m++) for(var s=0;s<=st;s++) timeTmp+=(h>9?h:'0'+h)+':'+(m>9?m:'0'+m)+':'+(s>9?s:'0'+s)+' ' result=timeTmp.split(' '); result.pop(); return result;
a8849516 2017-06-06
  • 打赏
  • 举报
回复
exports.cqssc=function(data){ var actionNo=data.number.substr(9,3)-(-1); if(actionNo>120) actionNo=120; var conf=createTimeProcess(); if(actionNo>=120) actionNo=1; var d=conf[actionNo-1].split(':'); var date=new Date(); var time=date.getTime(); var delay=10000; date.setSeconds(0); date.setHours(d[0]); date.setMinutes(d[1]); return 10000; //
a8849516 2017-06-06
  • 打赏
  • 举报
回复
我也说不清楚,反正采集的数据是20706050-032 这样,就正常, 如果是20706050032就不正常,但是数据库里面能找到20706050032 网站是自动生成期号的,即使我不采集,他也会显示出20706050-032,每10分钟自动加1期,20706050-033--20706050-034,这个时间和期号是固定对应的。
果酱很好吃 2017-06-06
  • 打赏
  • 举报
回复
不能理解了,既然都能进入数据库,那么你就在入库或者说显示的时候,更改一下期号不就行了?

echo substr('2070605032',0,8).'-'.substr('2070605032',-3,3);//20706050-032
a8849516 2017-06-06
  • 打赏
  • 举报
回复


上面带(-)的是系统自动生成的,,,不一样,就出错
a8849516 2017-06-06
  • 打赏
  • 举报
回复
可以采集进数据库,但是少个-的数据就会报错 也就是说我采集的2070605-032 这个期号就正常,采集锦2070605032,就不正常
xuzuning 2017-06-06
  • 打赏
  • 举报
回复
小哥哥,你的 var reg=/<row expect="([\d\-]+?)" opencode="([\d\,]+?)" opentime="([\d\:\- ]+?)"/; // 本身就可匹配 20170606043 和 20170606-043 还在拘泥什么呢?
a8849516 2017-06-06
  • 打赏
  • 举报
回复
$src = 'http://f.apiplus.cn/cqssc.xml'; $src .= '?_='.time(); $xml = file_get_contents(urldecode($src)); $xml = simplexml_load_string($xml); $data = array(); for ($i = 0,$count = count($xml->row); $i < $count; $i++) { $p = $xml->row[$i]->attributes()->expect; $tmp = array( 'expect' => substr($p,0,8).'-'.substr($p,-3,3),//开奖期号 'opencode' => current($xml->row[$i]->attributes()->opencode),//开奖号码 'opentime' => current($xml->row[$i]->attributes()->opentime),//开奖时间 ); $data[] = $tmp; } $json = json_encode($data); echo 'json 格式<br>'; echo $json; echo '<hr>'; echo '数组格式:'; echo "<pre>"; print_r(json_decode($json,true)); echo "</pre>"; /* json 格式 [{"expect":"20170606-060","opencode":"4,3,6,7,2","opentime":"2017-06-06 16:00:40"},{"expect":"20170606-059","opencode":"1,3,6,6,4","opentime":"2017-06-06 15:50:40"},{"expect":"20170606-058","opencode":"9,1,7,4,9","opentime":"2017-06-06 15:40:40"},{"expect":"20170606-057","opencode":"4,5,6,0,1","opentime":"2017-06-06 15:30:40"},{"expect":"20170606-056","opencode":"1,8,0,1,3","opentime":"2017-06-06 15:20:40"}] 数组格式: Array ( [0] => Array ( [expect] => 20170606-060 [opencode] => 4,3,6,7,2 [opentime] => 2017-06-06 16:00:40 ) [1] => Array ( [expect] => 20170606-059 [opencode] => 1,3,6,6,4 [opentime] => 2017-06-06 15:50:40 ) [2] => Array ( [expect] => 20170606-058 [opencode] => 9,1,7,4,9 [opentime] => 2017-06-06 15:40:40 ) [3] => Array ( [expect] => 20170606-057 [opencode] => 4,5,6,0,1 [opentime] => 2017-06-06 15:30:40 ) [4] => Array ( [expect] => 20170606-056 [opencode] => 1,8,0,1,3 [opentime] => 2017-06-06 15:20:40 ) ) */ 这个代码貌似不采集啊
a8849516 2017-06-06
  • 打赏
  • 举报
回复
做成xml好么
果酱很好吃 2017-06-06
  • 打赏
  • 举报
回复

$src = 'http://f.apiplus.cn/cqssc.xml';
$src .= '?_='.time();
$xml = file_get_contents(urldecode($src));
$xml = simplexml_load_string($xml);
$data = array();
for ($i = 0,$count = count($xml->row); $i < $count; $i++) {
	$p = $xml->row[$i]->attributes()->expect;
	$tmp = array(
		'expect' => substr($p,0,8).'-'.substr($p,-3,3),//开奖期号
		'opencode' => current($xml->row[$i]->attributes()->opencode),//开奖号码
		'opentime' => current($xml->row[$i]->attributes()->opentime),//开奖时间
	);
	$data[] = $tmp;
}
$json = json_encode($data);
echo 'json 格式<br>';
echo $json;

echo '<hr>';
echo '数组格式:';
echo "<pre>";
print_r(json_decode($json,true));
echo "</pre>";
/*
json 格式
[{"expect":"20170606-060","opencode":"4,3,6,7,2","opentime":"2017-06-06 16:00:40"},{"expect":"20170606-059","opencode":"1,3,6,6,4","opentime":"2017-06-06 15:50:40"},{"expect":"20170606-058","opencode":"9,1,7,4,9","opentime":"2017-06-06 15:40:40"},{"expect":"20170606-057","opencode":"4,5,6,0,1","opentime":"2017-06-06 15:30:40"},{"expect":"20170606-056","opencode":"1,8,0,1,3","opentime":"2017-06-06 15:20:40"}]
数组格式:
Array
(
    [0] => Array
        (
            [expect] => 20170606-060
            [opencode] => 4,3,6,7,2
            [opentime] => 2017-06-06 16:00:40
        )

    [1] => Array
        (
            [expect] => 20170606-059
            [opencode] => 1,3,6,6,4
            [opentime] => 2017-06-06 15:50:40
        )

    [2] => Array
        (
            [expect] => 20170606-058
            [opencode] => 9,1,7,4,9
            [opentime] => 2017-06-06 15:40:40
        )

    [3] => Array
        (
            [expect] => 20170606-057
            [opencode] => 4,5,6,0,1
            [opentime] => 2017-06-06 15:30:40
        )

    [4] => Array
        (
            [expect] => 20170606-056
            [opencode] => 1,8,0,1,3
            [opentime] => 2017-06-06 15:20:40
        )

)
*/
a8849516 2017-06-06
  • 打赏
  • 举报
回复
把这个网页的内容
像这个类型传输出来
或者在采集袋面里改一下把采集到的内容中间加个(-)
option:{ //
host:"f.apiplus.net", //
timeout:50000, //
path: '/cqssc.xml', //
headers:{ //
"User-Agent": "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0) " //
} //
}, //
parse:function(str){ //
try{ //
str=str.substr(0,200); //
var reg=/<row expect="([\d\-]+?)" opencode="([\d\,]+?)" opentime="([\d\:\- ]+?)"/; //
var m; //
if(m=str.match(reg)){ //
return { //
type:1, //
time:m[3], //
number:m[1], //
data:m[2] //
}; //
} //
}catch(err){ //
throw('--------解析数据不正确');
瞄了个猫 2017-06-06
  • 打赏
  • 举报
回复

<?php
$url="http://f.apiplus.cn/cqssc.xml";
$con=file_get_contents($url);
$con=simpalexml_load_string($con);
foreach($con as $r){
   foreach($r->attribute() as $k=>$v){
    if($k=="expect"){
          $v=join("-",str_split($v,8));
}    
   echo $k.$v."<br>";
}
}
?>
a8849516 2017-06-06
  • 打赏
  • 举报
回复
哪个好心的大神帮处理下啊
a8849516 2017-06-06
  • 打赏
  • 举报
回复
哦,是我没说明白,我是用NODE采集的
他只能采集这样的XML格式啊
这样的没法采集啊
xuzuning 2017-06-06
  • 打赏
  • 举报
回复
你主贴的代码(去掉 $src .= '?_='.time();)得到


采集地址:http://f.apiplus.cn/cqssc.xml

2017-06-06 13:35:12共采集到5行开奖数据:

开奖期号:20170606-043
开奖号码:9,8,5,5,9
开奖时间:2017-06-06 13:10:40

开奖期号:20170606-042
开奖号码:9,0,8,1,4
开奖时间:2017-06-06 13:00:40

开奖期号:20170606-041
开奖号码:0,5,3,5,7
开奖时间:2017-06-06 12:50:40

开奖期号:20170606-040
开奖号码:9,6,8,6,0
开奖时间:2017-06-06 12:40:40

开奖期号:20170606-039
开奖号码:3,5,7,8,1
开奖时间:2017-06-06 12:30:40
有什么不对吗?
a8849516 2017-06-06
  • 打赏
  • 举报
回复
<?php //header('content-type:text/xml;charset=utf-8'); $src = 'http://f.apiplus.cn/cqssc.xml'; $xml = file_get_contents(urldecode($src)); $xml = simplexml_load_string($xml); foreach($xml->row as $r) { foreach($r->attributes() as $k=>$v) { if($k == "expect") $v = join("-", str_split($v, 8)); echo "$k => $v\n"; } } 显示不对。。代码改怎么该呢
加载更多回复(1)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧