PHP - scraping web con PHP Simple HTML DOM error de captcha

 
Vista:
sin imagen de perfil
Val: 27
Ha aumentado su posición en 5 puestos en PHP (en relación al último mes)
Gráfica de PHP

scraping web con PHP Simple HTML DOM error de captcha

Publicado por dave (13 intervenciones) el 31/07/2019 23:51:44
Buenas no se si a alguien le apareció este error.
estoy trabajando con simple html dom, hasta ayer normal el trabajo de con las paginas pero me salio un error, al continuar con el raspado de una pagina.

Warning: file_get_contents(https://www.plusvalia.com/departamentos-en-venta-en-quito-pagina-9.html): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in C:\xampp\htdocs\scrapcsv\ecuador\quito\simple_html_dom.php on line 136


luego de verificar la pagina al intentar ingresar me pide:


003


mi consulta es si hay alguna manera de pasar eso y seguir con el raspado de la pagina intente de varias maneras pero aun no logro dar con algún método.
adjunto mi código de raspado:

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
<?php
 
$db = new PDO('mysql:host=localhost;dbname=infosantacruz;charset=utf8mb4', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
 
require 'simple_html_dom.php';
 
 
 
$url = 'https://www.plusvalia.com/departamentos-en-venta-en-quito-pagina-9.html';
 
$html = file_get_html($url);
 
$posts = $html->find('div[class=posting-header]');
 
foreach ($posts as $post){
 
    $link = $post->find('h3 a', 0);
    $url = $link->attr['href'];
    $title = $link->innertext;
 
 
 
    $url = 'https://www.plusvalia.com'.$url;
 
 
    echo "<table border='2'>";
    echo "<tr>";
    echo "<td>",$url,"\n","</td>";
    echo "</tr>";
    echo "</table>";
 
    $html = file_get_html($url);
 
    $posts = $html->find('div[id=main-container]');
 
    foreach ($posts as $post){
 
 
        $titulo = $post->find('div[class=section-title] h1', 0);
 
 
 
        $prec = $post->find('div[class=block-price block-row] div', 1);
        $prec2 = $post->find('div[class=row css-border-n] span', 1);
        $precio = $prec.$prec2;
 
 
        //$telefono = $post->find('div[class=mdl mdlContent-simpleCenter mdl-modal mdl-modal-postlead] a', 0)->attr['href'];
 
 
 
        $latitud = $post->find('div[class=article-map] img', 0)->attr['src'];
        $longitud = $post->find('div[class=article-map] img', 0)->attr['src'];
 
 
 
        $a = $post->find('li[class=icon-feature] b', 0);
        $b = $post->find('li[class=icon-feature] span', 0);
        $datos1 = $a.$b;
 
 
        $c = $post->find('li[class=icon-feature] b', 1);
        $d = $post->find('li[class=icon-feature] span', 1);
        $datos2 =  $c.$d;
 
 
        $e = $post->find('li[class=icon-feature] b', 2);
        $f = $post->find('li[class=icon-feature] span', 2);
        $datos3 = $e.$f;
 
 
        $g = $post->find('li[class=icon-feature] b', 3);
        $h = $post->find('li[class=icon-feature] span', 3);
        $datos4 = $g.$h;
 
 
        $i = $post->find('li[class=icon-feature] b', 4);
        $j = $post->find('li[class=icon-feature] span', 4);
        $datos5 = $i.$j;
 
 
        $k = $post->find('li[class=icon-feature] b', 5);
        $l = $post->find('li[class=icon-feature] span', 5);
        $datos6 = $k.$l;
 
 
        $m = $post->find('li[class=icon-feature] b', 6);
        $n = $post->find('li[class=icon-feature] span', 6);
        $datos7 = $m.$n;
 
 
 
 
 
        $publi = $post->find('section[class=general-section article-section article-section-description] h5', 0);
 
 
 
 
        $serv  = $post->find('section[class=general-section article-section] h4', 1);
        $serv1 = $post->find('section[class=general-section article-section] h4', 2);
        $serv2 = $post->find('section[class=general-section article-section] h4', 3);
        $serv3 = $post->find('section[class=general-section article-section] h4', 4);
        $serv4 = $post->find('section[class=general-section article-section] h4', 5);
        $serv5 = $post->find('section[class=general-section article-section] h4', 6);
        $serv6 = $post->find('section[class=general-section article-section] h4', 7);
        $serv7 = $post->find('section[class=general-section article-section] h4', 8);
 
        $observa = $serv.$serv1.$serv2.$serv3.$serv4.$serv5.$serv6.$serv7;
 
 
 
 
 
 
        $zona = $post->find('div[class=section-location] b', 0);
 
 
        $link = $post->find('figure img', 0);
        $img = $link->attr['data-flickity-lazyload'];
        //$link = $post->find('div img', 1);
        //$im = $link->attr['src'];
        $im = $post->find('div[class=gallery-item js-openDevelopmentMultimedia] img', 0)->attr['src'];
        $imagen = $img.$im;
 
 
 
 
        $link = $post->find('figure img', 1);
        $img1 = $link->attr['data-flickity-lazyload'];
        $im1 = $post->find('div[class=gallery-item js-openDevelopmentMultimedia] img', 1)->attr['src'];
        //$link = $post->find('div img', 2);
        //$im1 = $link->attr['src'];
        $imagen1 = $img1.$im1;
 
 
        $link = $post->find('figure img', 2);
        $img2 = $link->attr['data-flickity-lazyload'];
        $im2 = $post->find('div[class=gallery-item js-openDevelopmentMultimedia] img', 2)->attr['src'];
        //$link = $post->find('div img', 3);
        //$im2 = $link->attr['src'];
        $imagen2 = $img2.$im2;
 
 
        $link = $post->find('figure img', 3);
        $img3 = $link->attr['data-flickity-lazyload'];
        $im3 = $post->find('div[class=gallery-item js-openDevelopmentMultimedia] img', 3)->attr['src'];
        //$link = $post->find('div img', 4);
        //$im3 = $link->attr['src'];
        $imagen3 = $img3.$im3;
 
 
 
        $link = $post->find('figure img', 4);
        $imagen4 = $link->attr['data-flickity-lazyload'];
 
 
 
 
 
 
 
        echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
 
        echo "<table border='2'>";
        echo "<tr>";
        echo "<td>",$titulo,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$precio,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$longitud,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$latitud,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$datos1,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$datos2,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$datos3,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$datos4,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$datos5,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$datos6,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$datos7,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$publi,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        //echo "<td>",$telefono,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$observa,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$zona,"\n","</td>";
        echo "</tr>";
        echo "<tr>";
        echo "<td>",$imagen,"\n","</td>";
        echo "<tr>";
        echo "<td>",$imagen1,"\n","</td>";
        echo "<tr>";
        echo "<td>",$imagen2,"\n","</td>";
        echo "<tr>";
        echo "<td>",$imagen3,"\n","</td>";
        echo "<tr>";
        echo "<td>",$imagen4,"\n","</td>";
        echo "</tr>";
        echo "<td>",$im,"\n","</td>";
        echo "<tr>";
        echo "<td>",$im1,"\n","</td>";
        echo "<tr>";
        echo "<td>",$im2,"\n","</td>";
        echo "<tr>";
        echo "<td>",$im3,"\n","</td>";
        echo "</tr>";
        echo "</table>";
 
 
$stmt = $db->prepare("INSERT INTO quitoplusdptos(titulo, precio, longitud, latitud, datos1, datos2, datos3, datos4, datos5, datos6, datos7, publi, telefono, observa, zona, url, imagen, imagen1, imagen2, imagen3, imagen4) VALUES(:titulo, :precio, :longitud, :latitud, :datos1, :datos2, :datos3, :datos4, :datos5, :datos6, :datos7, :publi, :telefono, :observa, :zona, :url, :imagen, :imagen1, :imagen2, :imagen3, :imagen4)");
 
        $stmt->execute(array(
            ':titulo' => $titulo,
            ':precio' => $precio,
            ':longitud' => $longitud,
            ':latitud' => $latitud,
            ':datos1' => $datos1,
            ':datos2' => $datos2,
            ':datos3' => $datos3,
            ':datos4' => $datos4,
            ':datos5' => $datos5,
            ':datos6' => $datos6,
            ':datos7' => $datos7,
            ':publi' => $publi,
            ':telefono' => $telefono,
            ':observa' => $observa,
            ':zona' => $zona,
            ':url' => $url,
            ':imagen' => $imagen,
            ':imagen1' => $imagen1,
            ':imagen2' => $imagen2,
            ':imagen3' => $imagen3,
            ':imagen4' => $imagen4));
 
        $affected_rows = $stmt->rowCount();
 
 
    }
 
}


Me seria de mucha ayuda si alguien pudo solucionar alguna vez esto, o si conocen algún método para pasar esto... Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de santi
Val: 588
Bronce
Ha mantenido su posición en PHP (en relación al último mes)
Gráfica de PHP

scraping web con PHP Simple HTML DOM error de captcha

Publicado por santi (204 intervenciones) el 01/08/2019 23:27:06
Hola,

prueba con curl -> https://www.php.net/manual/es/book.curl.php pero la gracias del captcha es para evitar este tipo de scraping... Si creas un script para acceder a un formulario de forma automática, no deja de ser un robot por lo que veo muy difícil conseguir que puedas enviar un formulario..

Y no lo he probado pero igual con curl funciona,

prueba a ver ;)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar