陈德本 6 years ago
parent
commit
aa9797c7f0
1 changed files with 28 additions and 31 deletions
  1. 28 31
      App/Api/Model/Dataoke.php

+ 28 - 31
App/Api/Model/Dataoke.php

@@ -15,31 +15,26 @@ class Dataoke
     {
         $ql = QueryList::html($content);
 
-// 元数据采集规则
-        $rules = [
-            'link' => ["a", "href"]
-        ];
-// 切片选择器
         $rt = $ql->find("a")->attrs('href');
         $data = $rt->all();
         $data = array_unique($data);
-        foreach ($data as $url) {
+        foreach ($data as $k => $url) {
 //            if (strstr($url, "tao.php") === false) {
 //                continue;
 //            }
-            $query=parse_url($url);
+            $query = parse_url($url);
 
             $t = parse_query($query['query']);
             if ($t['kw']) {
-                $q=[];
-                if ($t['cid']){
-                    $q['cid']=$t['cid'];
+                $q = [];
+                if ($t['cid']) {
+                    $q['cid'] = $t['cid'];
                 }
-                if ($t['pid']){
-                    $q['pid']=$t['pid'];
+                if ($t['pid']) {
+                    $q['pid'] = $t['pid'];
                 }
-                if ($t['bids']){
-                    $q['bids']=$t['bids'];
+                if ($t['bids']) {
+                    $q['bids'] = $t['bids'];
                 }
 
                 //elseif ($t['cid']){
@@ -48,20 +43,22 @@ class Dataoke
 //                    $d=$t;
 //                    unset($d['kw']);
 //                }
-                if (count($q)>0){
-                    $s="?".http_build_query($q);
-                }else{
-                    $s="";
+                if (count($q) > 0) {
+                    $s = "?" . http_build_query($q);
+                } else {
+                    $s = "";
                 }
-                $new_url="/kw/" . $t['kw'] . ".html".$s;
+                $new_url = "/kw/" . $t['kw'] . ".html" . $s;
 
-                $content = str_replace($url, $new_url, $content);
-            }else{
+                $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
+            } else {
                 if ($t['cid']) {
-                    $content = str_replace($url, "/category/" . $t['cid'] . ".html", $content);
-                }else{
+                    $new_url = "/category/" . $t['cid'] . ".html";
+                    $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
+                } else {
                     if ($t['id']) {
-                        $content = str_replace($url, "/product/" . $t['id'] . ".html", $content);
+                        $new_url = "/product/" . $t['id'] . ".html";
+                        $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
                     }
                 }
 
@@ -73,13 +70,13 @@ class Dataoke
 //            }
 
         }
-        $content=str_replace('"/tao.php?r=p"', '"/pages/fengqiang.html"', $content);
-        $content=str_replace('"/tao.php?r=nine"', '"/pages/nine.html"', $content);
-        $content=str_replace('"/tao.php?r=ddq"', '"/pages/dongdong.html"', $content);
-        $content=str_replace('"/tao.php?r=l"', '"/pages/haohuo.html"', $content);
-        $content=str_replace('"/tao.php?r=index/index&u=1350274"', '"/"', $content);
-        $content=str_replace('href="/tao.php?r=index/index"', 'href="/"', $content);
-        $content=str_replace('https://cmsstatic.ffquan.cn//js/new_home.js', "/static/new_home.js", $content);
+        $content = str_replace('"/tao.php?r=p"', '"/pages/fengqiang.html"', $content);
+        $content = str_replace('"/tao.php?r=nine"', '"/pages/nine.html"', $content);
+        $content = str_replace('"/tao.php?r=ddq"', '"/pages/dongdong.html"', $content);
+        $content = str_replace('"/tao.php?r=l"', '"/pages/haohuo.html"', $content);
+        $content = str_replace('"/tao.php?r=index/index&u=1350274"', '"/"', $content);
+        $content = str_replace('href="/tao.php?r=index/index"', 'href="/"', $content);
+        $content = str_replace('https://cmsstatic.ffquan.cn//js/new_home.js', "/static/new_home.js", $content);
 //        $content=str_replace('index.php', "tao.php", $content);
         return $content;
     }