Dataoke.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Heanup\App\Api\Model;
  3. use QL\QueryList;
  4. use function GuzzleHttp\Psr7\parse_query;
  5. class Dataoke
  6. {
  7. public static function parse($content)
  8. {
  9. $ql = QueryList::html($content);
  10. // 元数据采集规则
  11. $rules = [
  12. 'link' => ["a", "href"]
  13. ];
  14. // 切片选择器
  15. $rt = $ql->find("a")->attrs('href');
  16. $data = $rt->all();
  17. $data = array_unique($data);
  18. foreach ($data as $url) {
  19. // if (strstr($url, "tao.php") === false) {
  20. // continue;
  21. // }
  22. $_url=str_replace("tao.php", "", $url);
  23. $_url=str_replace("index.php", "", $_url);
  24. $t = parse_query($_url);
  25. if ($t['kw']) {
  26. // if ($t['bids']){
  27. // $new_url="/kw/" . $t['kw'] . ".html?bids=".$t['bids'];
  28. // }elseif ($t['cid']){
  29. // $new_url="/kw/" . $t['kw'] . ".html?cid=".$t['cid'];
  30. // } else{
  31. // $d=$t;
  32. // unset($d['kw']);
  33. // }
  34. $new_url="/kw/" . $t['kw'] . ".html?".http_build_query($t);
  35. $content = str_replace($url, $new_url, $content);
  36. }else{
  37. if ($t['cid']) {
  38. $content = str_replace($url, "/category/" . $t['cid'] . ".html", $content);
  39. }else{
  40. if ($t['id']) {
  41. $content = str_replace($url, "/product/" . $t['id'] . ".html", $content);
  42. }
  43. }
  44. }
  45. ///index.php?r=index
  46. // if ($url=="/index.php?r=index"){
  47. // $content = str_replace($url, "/" , $content);
  48. // }
  49. }
  50. $content=str_replace('"/tao.php?r=p"', '"/pages/fengqiang.html"', $content);
  51. $content=str_replace('"/tao.php?r=nine"', '"/pages/nine.html"', $content);
  52. $content=str_replace('"/tao.php?r=ddq"', '"/pages/dongdong.html"', $content);
  53. $content=str_replace('"/tao.php?r=l"', '"/pages/haohuo.html"', $content);
  54. $content=str_replace('"/tao.php?r=index/index&u=1350274"', '"/"', $content);
  55. $content=str_replace('https://cmsstatic.ffquan.cn//js/new_home.js', "/static/new_home.js", $content);
  56. // $content=str_replace('index.php', "tao.php", $content);
  57. return $content;
  58. }
  59. }