Dataoke.php 2.3 KB

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