Dataoke.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 (count($q) > 0) {
  33. $s = "?" . http_build_query($q);
  34. } else {
  35. $s = "";
  36. }
  37. if ($t['kw']) {
  38. $new_url = "/kw/" . $t['kw'] . ".html" . $s;
  39. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  40. } else {
  41. if ($t['cid']) {
  42. $new_url = "/category/" . $t['cid'] . ".html".$s;
  43. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  44. } else {
  45. if ($t['id']) {
  46. $new_url = "/product/" . $t['id'] . ".html";
  47. $content = str_replace('"' . $url . '"', '"' . $new_url . '"', $content);
  48. }
  49. }
  50. }
  51. ///index.php?r=index
  52. // if ($url=="/index.php?r=index"){
  53. // $content = str_replace($url, "/" , $content);
  54. // }
  55. }
  56. $content = str_replace('"/tao.php?r=p"', '"/pages/fengqiang.html"', $content);
  57. $content = str_replace('"/tao.php?r=nine"', '"/pages/nine.html"', $content);
  58. $content = str_replace('"/tao.php?r=ddq"', '"/pages/dongdong.html"', $content);
  59. $content = str_replace('"/tao.php?r=l"', '"/pages/haohuo.html"', $content);
  60. $content = str_replace('"/tao.php?r=index/index&u=1350274"', '"/"', $content);
  61. $content = str_replace('href="/tao.php?r=index/index"', 'href="/"', $content);
  62. $content = str_replace('https://cmsstatic.ffquan.cn//js/new_home.js', "/static/new_home.js", $content);
  63. // $content=str_replace('index.php', "tao.php", $content);
  64. return $content;
  65. }
  66. }