-
Notifications
You must be signed in to change notification settings - Fork 13
/
Execute.php
41 lines (34 loc) · 1.18 KB
/
Execute.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
require("spider/GoodsCrawler.php");
require("spider/ShopCrawler.php");
/**
* @author: ys <4932004@qq.com>
*/
//任意淘宝连接都可以解析出店铺id 一键爬取淘宝店铺所有信息
$url = 'https://shop106503118.taobao.com/';
$crawler = new ShopCrawler();
$reconnectCount = 3;//重连次数
$timeout = 10000; //等待页面超时时间
$delayTime = 1.5; //延迟执行,防止频繁访问被封
$crawler->request($url, $reconnectCount, $timeout, $delayTime);
$shopId = $crawler->getShopId();//获取店铺id
//获取第一页商品连接和信息
$shop = new ShopCrawler();
$shop->request($shop->getShopHref($shopId)); //打开店铺
$info = $shop->getInfo(); //获取店铺信息
var_dump($info);
$goodsListUrl = $shop->getGoodsListUrl();//获取所有的商品连接
foreach($goodsListUrl as $url)
{
$goods = new GoodsCrawler();
$goods->request($url, $reconnectCount, $timeout, $delayTime);
var_dump($goods->getBaseInfo());
var_dump($goods->getDetailList());
$imgList = $goods->getGoodsImgList();
var_dump($imgList);
foreach($imgList as $imgUrl)
{
//GoodsCrawler::downloadImg($imgUrl, './img/');
}
unset($goods);
}