-
Notifications
You must be signed in to change notification settings - Fork 0
/
xxhh.php
executable file
·154 lines (134 loc) · 3.34 KB
/
xxhh.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/***
* 采集xxhh.com
*
* */
ignore_user_abort(1);
include_once('./config.php');
include ('./snoopy.class.php');
set_time_limit(0);
#获取页面url
#获取合法url
#抓取指定页面的内容
#存库
$snoopy = new Snoopy();
/**
// $sourceURL = "http://www.3jy.com/tag/12/2.html";
$contentUrl = "http://wap.xxhh.com/418928.html";
// $snoopy->fetchlinks($sourceURL);
// $snoopy->fetchtext($sourceURL);
$snoopy->fetch($contentUrl);
$return = $snoopy->results;
$regex3="/<title>.*?<\/title>/ism";
$regex3 = '/<title>(.*)<\/title>/i';
if(preg_match_all($regex3, $return, $title)){
$_t = explode('_', $title[1][0]);
$title = $_t;
}else{
echo '0';
}print_r($title);
$id = number($contentUrl);
$regex4="/<pre id=\"pre-".$id."\".*?>.*?<\/pre>/ism";
if(preg_match_all($regex4, $return, $content)){
}else{
$content = '0';
}
print_r($content);
die();
**/
// var_dump(checkUrl($contentUrl));
// exit();
for ($i=2; $i < 10000; $i++) {
$sourceURL = "http://wap.xxhh.com/duanzi/page/".$i."/";
$snoopy = new Snoopy();
$snoopy->fetchlinks($sourceURL);
$links = $snoopy->results;
$has = 0;
foreach ($links as $key => $value) {
//$value
//echo $value."<br />";
if(checkUrl($value)){
//echo 'zzz';
$has = 1;
saveInfo($value,$db);
//sleep(2);
}
}
if($has == 0){
die();
}
}
function checkUrl($url){
//echo $url."<br/>";
$part = explode('/', $url);
$part1 = explode('.', $url);
// var_dump(strpos($url, 'youmo'));
// var_dump(strpos($url, '.htm') );
// echo count($part) ;
//echo count($part1);
if( strpos($url, 'wap.xxhh.com/')&& strpos($url, '.htm')&&(number($part1[2]) > 0 ) &&( count($part) ==4) &&(count($part1)==4) ){
// var_dump(strpos($url, 'youmo'));
// var_dump(strpos($url, '.htm') );
//echo 'ok';
//echo $url."<br/>";
//echo $part1[2]."<br/>";
return true;
}else{
return false;
}
}
function saveInfo($url,$db){
// echo 'saveInfo';
$snoopy = new Snoopy();
$snoopy->fetch($url);
$return = $snoopy->results;
// $regex3="/<title>.*?<\/title>/ism";
$regex3 = '/<title>(.*)<\/title>/i';
if(preg_match_all($regex3, $return, $title)){
$_t = explode('_', $title[1][0]);
$title = $_t[0];
}else{
$title = '0';
}
$id = number($url);
$regex4="/<pre id=\"pre-".$id."\".*?>.*?<\/pre>/ism";
if(preg_match_all($regex4, $return, $content)){
}else{
$content = '0';
}
$table = 'joke';
$data['title'] = $title;
$data['content'] = ($content[0][0]);
$data['url'] = $url;
$data['mark'] = number($url);
$data['site'] = 2;
//print_r($data);
$r = $db->insert($table,$data);
$sql = $db->getLastSql();
//echo "<br>";
saveSql($sql);
}
function number($str)
{
return preg_replace('/\D/s', '', $str);
}
function saveSql($sql){
file_put_contents('./data/sql_log_xxhh.txt', $sql.";\n", FILE_APPEND);
}
/**
// $return = $snoopy->results;
// $regex3="/<title>.*?<\/title>/ism";
// if(preg_match_all($regex3, $return, $title)){
// print_r($title);
// }else{
// echo '0';
// }
// // print_r($return);
// $regex4="/<div class=\"content-nr\". * ?>.*? < \/div>/ism";
// if(preg_match_all($regex4, $return, $matches)){
// print_r($matches);
// }else{
// echo '0';
// }
**/
?>