Dataoke.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. $q = [];
  20. if ($t['cid']) {
  21. $q['cid'] = $t['cid'];
  22. }
  23. if ($t['pid']) {
  24. $q['pid'] = $t['pid'];
  25. }
  26. if ($t['bids']) {
  27. $q['bids'] = $t['bids'];
  28. }
  29. if ($t['original_id']){
  30. $q['original_id'] = $t['original_id'];
  31. }
  32. if ($t['kw']) {
  33. unset($q['kw']);
  34. if (count($q) > 0) {
  35. $s = "?" . http_build_query($q);
  36. } else {
  37. $s = "";
  38. }
  39. $new_url = "/kw/" . $t['kw'] . ".html" . $s;
  40. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  41. } else {
  42. if ($t['cid']) {
  43. unset($q['cid']);
  44. if (count($q) > 0) {
  45. $s = "?" . http_build_query($q);
  46. } else {
  47. $s = "";
  48. }
  49. $new_url = "/category/" . $t['cid'] . ".html".$s;
  50. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  51. } else {
  52. if ($t['id']) {
  53. $new_url = "/product/" . $t['id'] . ".html";
  54. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  55. }
  56. }
  57. }
  58. ///index.php?r=index
  59. // if ($url=="/index.php?r=index"){
  60. // $content = str_replace($url, "/" , $content);
  61. // }
  62. }
  63. $content = str_replace('"/tao.php?r=p"', '"/pages/fengqiang.html"', $content);
  64. $content = str_replace('"/tao.php?r=nine"', '"/pages/nine.html"', $content);
  65. $content = str_replace('"/tao.php?r=ddq"', '"/pages/dongdong.html"', $content);
  66. $content = str_replace('"/tao.php?r=l"', '"/pages/haohuo.html"', $content);
  67. $content = str_replace('"/tao.php?r=index/index&u=1350274"', '"/"', $content);
  68. $content = str_replace('href="/tao.php?r=index/index"', 'href="/"', $content);
  69. $content = str_replace('https://cmsstatic.ffquan.cn//js/new_home.js', "/static/new_home.js", $content);
  70. // $content=str_replace('index.php', "tao.php", $content);
  71. return $content;
  72. }
  73. }