php采集DEMO一个
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266 |
<!DOCTYPE html PUBLIC “- //W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <html xmlns=”http: //www.w3.org/1999/xhtml”> <head> <meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ /> <title>alibaba采集</title> <?php set_time_limit(0); function
_rand() { $length =26; $chars
= “0123456789abcdefghijklmnopqrstuvwxyz”; $max
= strlen ( $chars ) – 1; mt_srand((double)microtime() * 1000000); $string
= ”; for ( $i
= 0; $i < $length ; $i ++) { $string
.= $chars [mt_rand(0, $max )]; } return
$string ; } error_reporting (0); ini_set (‘html_errors’,false); ini_set (‘display_errors’,false); mysql_pconnect(“localhost”, “root”, “password”) or die
(“Could not connect” . mysql_error()); mysql_select_db(“company”); mysql_query(“SET NAMES ‘UTF8′”); if ( $_GET [ ‘page‘ ]){ $page
= $_GET [ ‘page‘ ]; } else { $page
= ’1′; } $HTTP_SESSION =_rand(); $HTTP_SESSION ; $HTTP_URL =”http: //www.alibaba.com/corporations/jiangmen/CN——————————–/”.$page.”.html”; $ch = curl_init(); curl_setopt ( $ch ,CURLOPT_URL, $HTTP_URL ); curl_setopt( $ch ,CURLOPT_RETURNTRANSFER,true); curl_setopt( $ch ,CURLOPT_USERAGENT,”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)”); $res = curl_exec( $ch ); curl_close ( $ch ); preg_match_all(‘/href\s*=\s*[ "|\‘]?([^\s" \‘>]*).en.alibaba.com\”/i’, $res , $arr ); foreach ( $arr [1] as
$a => $web ){ $HTTP_SESSION =_rand(); $HTTP_SESSION ; $HTTP_Server = $web ; $HTTP_URL =”.en.alibaba.com/contactinfo.html”; $ch1
= curl_init(); curl_setopt ( $ch1 ,CURLOPT_URL, $HTTP_Server . $HTTP_URL ); curl_setopt( $ch1 ,CURLOPT_RETURNTRANSFER,true); curl_setopt( $ch1 ,CURLOPT_USERAGENT,”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)”); $res1
= curl_exec( $ch1 ); curl_close ( $ch1 ); preg_match(“/contactName(.*?)<\/a>/s”, $res1 , $name ); $name
= strip_tags ( $name [1]); //$name = str_replace(“\”",”",$name); //$name = str_replace(“>”,”",$name); $name
= trim( $name ); preg_match(“/Company Name:(.*?)<\/td>/s”, $res1 , $Cname ); $Cname
= trim( strip_tags ( $Cname [1])); preg_match(“/Street Address:(.*?)<\/td>/s”, $res1 , $Add ); $Add
= trim( strip_tags ( $Add [1])); preg_match(“/City:(.*?)<\/td>/s”, $res1 , $City ); $City
= trim( strip_tags ( $City [1])); preg_match(“/Province\/State:(.*?)<\/td>/s”, $res1 , $Pronvice ); $Pronvice
= trim( strip_tags ( $Pronvice [1])); preg_match(“/Country\/Region:(.*?)<\/td>/s”, $res1 , $Region ); $Region
= trim( strip_tags ( $Region [1])); preg_match(“/Zip:(.*?)<\/td>/s”, $res1 , $Zip ); $Zip
= trim( strip_tags ( $Zip [1])); preg_match(“/Telephone:(.*?)<\/td>/s”, $res1 , $Tel ); $Tel
= trim( strip_tags ( $Tel [1])); preg_match(“/Mobile Phone:(.*?)<\/td>/s”, $res1 , $Phone ); $Phone
= trim( strip_tags ( $Phone [1])); preg_match(“/Fax:(.*?)<\/td>/s”, $res1 , $Fax ); $Fax
= trim( strip_tags ( $Fax [1])); preg_match(“/Website:(.*?)<\/td>/s”, $res1 , $Web ); $Web
= trim( strip_tags ( $Web [1])); $result
= mysql_query(“ INSERT INTO alibaba ( Name, Company, Address, City, Province, Region, Zip, Tel, Phone, Fax, Web ) VALUES( ‘”.htmlspecialchars( $name ).”‘, ‘”.htmlspecialchars( $Cname ).”‘, ‘”.htmlspecialchars( $Add ).”‘, ‘”.htmlspecialchars( $City ).”‘, ‘”.htmlspecialchars( $Pronvice ).”‘, ‘”.htmlspecialchars( $Region ).”‘, ‘”.htmlspecialchars( $Zip ).”‘, ‘”.htmlspecialchars( $Tel ).”‘, ‘”.htmlspecialchars( $Phone ).”‘, ‘”.htmlspecialchars( $Fax ).”‘, ‘”.htmlspecialchars( $Web ).”‘ )”); } if ( $page
>= 29){ echo
“OVER!”; exit (); } else { echo
“<meta http-equiv=refresh content=’0; url=alibaba.php?page=”.++ $page .”‘>”; } ?> </head> <body> </body></html> |
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。