Youzan.php 821 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Ku\Spider;
  3. use Dever;
  4. class Youzan
  5. {
  6. public function rule()
  7. {
  8. return array
  9. (
  10. 'pic' => '<img src="(.*?)" alt="(.*?)"/>',
  11. 'name' => '<h3 class="goods-title">(.*?)</h3>',
  12. 'price' => '<em class="goods-rmb">¥</em>(.*?)</strong>',
  13. );
  14. }
  15. public function link($link)
  16. {
  17. if (strpos($link, 'h5.youzan.com')) {
  18. $temp = explode('/goods/', $link);
  19. $id = $temp[1];
  20. $link = 'https://detail.youzan.com/show/goods?alias=' . $id;
  21. }
  22. return $link;
  23. }
  24. public function replace($key, $data)
  25. {
  26. if ($key == 'price') {
  27. $data = str_replace('<span class="goods-activity">限时折扣</span>', '', $data);
  28. }
  29. return $data;
  30. }
  31. }