Dataoke.php 2.5 KB

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