Repository navigation
Expand file tree
/
Copy pathspiderone.php
More file actions
124 lines (85 loc) · 3.09 KB
/
Copy pathspiderone.php
File metadata and controls
124 lines (85 loc) · 3.09 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
require_once __DIR__.'/vendor/autoload.php';
use GuzzleHttp\RequestOptions;
use QL\QueryList;
use GuzzleHttp\Client;
use Administrator\ExampleFast\Lib\Utils;
define("DS", DIRECTORY_SEPARATOR);
define("publicDir", __DIR__.DS.'public');
define("htmlDir", publicDir.DS.'html');
define("imageDir", publicDir.DS.'image');
define("jsonDir", publicDir.DS.'json');
$baseUrl = "http://www.1fang.wang";
$baseHtml = htmlDir.DS.'index.html';
if ( ! file_exists($baseHtml)) {
$client = new Client(['base_uri' => $baseUrl]);
$result = $client->get(
'/', [
RequestOptions::SINK => $baseHtml
]
);
} else {
$html = file_get_contents($baseHtml);
}
$html = $html ? QueryList::html($html) : QueryList::get($baseUrl);
//$urls = $html->find('a')->attrs('href')->filter(
// function ($item) use ($baseUrl) {
// if ($item == "javascript:void(0);"
// || $item == "javacript:void(0);"
// || $item == "javascript:void(0)"
// || $item == ""
// || $item == "/"
// || $item == $baseUrl
// ) {
// return false;
// }
//
// return true;
// }
//);
//$title = $html->find('title')->text();
//$nav = $html->rules(
// [
// 'name' => ['a', 'text'],
// 'url' => ['a', 'href', '', function ($item) use ($baseUrl) { return $baseUrl.$item;}]
// ]
//)->range('div.list > li')->query()->getData()->toArray();
//$json_str = json_encode($nav, JSON_UNESCAPED_UNICODE);
//$result = file_put_contents(jsonDir.DS."nav.json", $json_str);
//if ($result) {
// echo "写入json成功" . PHP_EOL;
//}
// 资讯
$newsData = $html->rules([
'title' => ['a' , 'text'],
'url' => ['a', 'href','',function($item) use($baseUrl) { return $baseUrl . $item; }]
])->range('.body > .right > li')->query()->getData()->toArray();
// 动态
$async = $html->rules([
'title' => ['a', 'text'],
'url' => ['a', 'href']
])->range(".layui-carousel > div > .newslist > li")->query()->getData()->toArray();
// 置业顾问
$zygw = $html->rules([
'name' => ['div.name', 'text'],
'avthod' => ['img', 'src','', function($item) use($baseUrl) {return $baseUrl . $item; }]
])->range(".zygj > li")->query()->getData()->toArray();
# 热门楼盘
$hotHouse = $html->rules([
'title' => ['span.loupan','text'],
'url' => ['span.loupan > a', 'href','',function($item) use($baseUrl) {return $baseUrl.$item;}],
'price' => ['span:eq(2)','text']
])->range('.body > .left > .hotlist > li')->query()->getData()->toArray();
# 排行榜
$hot = $html->rules([
'title' => [' a > .title', 'text','',function($item) { $item = explode(
'-', $item); return $item[1];}],
'url' => ['a', 'href','',function($item) use($baseUrl) {return $baseUrl.$item;}],
'image' => ['a > img', 'src','',function($item) use($baseUrl) {return $baseUrl.$item;}],
'price' => ['div.price > span', 'text']
])->range('.paiming > .width > .item')->query()->getData()->toArray();
$xmls = Utils::xml_encode($hotHouse);
$result = file_put_contents(jsonDir.DS."nav.xml", $xmls);
if ($result) {
echo "写入xml成功" . PHP_EOL;
}