Dataoke.php 2.7 KB

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