Dataoke.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. $rt = $ql->find("a")->attrs('href');
  11. $data = $rt->all();
  12. $data = array_unique($data);
  13. foreach ($data as $k => $url) {
  14. // if (strstr($url, "tao.php") === false) {
  15. // continue;
  16. // }
  17. $query = parse_url($url);
  18. $t = parse_query($query['query']);
  19. if ($t['kw']) {
  20. $q = [];
  21. if ($t['cid']) {
  22. $q['cid'] = $t['cid'];
  23. }
  24. if ($t['pid']) {
  25. $q['pid'] = $t['pid'];
  26. }
  27. if ($t['bids']) {
  28. $q['bids'] = $t['bids'];
  29. }
  30. //elseif ($t['cid']){
  31. // $new_url="/kw/" . $t['kw'] . ".html?cid=".$t['cid'];
  32. // } else{
  33. // $d=$t;
  34. // unset($d['kw']);
  35. // }
  36. if (count($q) > 0) {
  37. $s = "?" . http_build_query($q);
  38. } else {
  39. $s = "";
  40. }
  41. $new_url = "/kw/" . $t['kw'] . ".html" . $s;
  42. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  43. } else {
  44. if ($t['cid']) {
  45. $new_url = "/category/" . $t['cid'] . ".html";
  46. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  47. } else {
  48. if ($t['id']) {
  49. $new_url = "/product/" . $t['id'] . ".html";
  50. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  51. }
  52. }
  53. }
  54. ///index.php?r=index
  55. // if ($url=="/index.php?r=index"){
  56. // $content = str_replace($url, "/" , $content);
  57. // }
  58. }
  59. $content = str_replace('"/tao.php?r=p"', '"/pages/fengqiang.html"', $content);
  60. $content = str_replace('"/tao.php?r=nine"', '"/pages/nine.html"', $content);
  61. $content = str_replace('"/tao.php?r=ddq"', '"/pages/dongdong.html"', $content);
  62. $content = str_replace('"/tao.php?r=l"', '"/pages/haohuo.html"', $content);
  63. $content = str_replace('"/tao.php?r=index/index&u=1350274"', '"/"', $content);
  64. $content = str_replace('href="/tao.php?r=index/index"', 'href="/"', $content);
  65. $content = str_replace('https://cmsstatic.ffquan.cn//js/new_home.js', "/static/new_home.js", $content);
  66. // $content=str_replace('index.php', "tao.php", $content);
  67. return $content;
  68. }
  69. }