web scrapping & wordpress

26
Web Scraping & WordPress César Aquino Maximiliano - @cesjam7

Upload: cesar-jefferson-aquino-maximiliano

Post on 12-Feb-2017

447 views

Category:

Internet


2 download

TRANSCRIPT

Page 1: Web Scrapping & WordPress

Web Scraping&

WordPress

César Aquino Maximiliano - @cesjam7

Page 2: Web Scrapping & WordPress

César J. Aquino Maximiliano@cesjam7

+ =

Page 3: Web Scrapping & WordPress

¿Qué es Web Scraping?

Web Scraping es una técnica utilizada

mediante software para extraer

información de sitios web.

Page 4: Web Scrapping & WordPress

Técnicas para hacer Web Scraping■ Copy & Paste

■ Expresiones regulares

■ Protocolo HTTP

■ Parses HTML

■ Aplicaciones para Web Scraping

Page 5: Web Scrapping & WordPress

Técnicas para hacer Web Scraping■ Copy & Paste

■ Expresiones regulares

■ Protocolo HTTP

■ Parses HTML

■ Aplicaciones para Web Scraping

Page 6: Web Scrapping & WordPress
Page 7: Web Scrapping & WordPress
Page 8: Web Scrapping & WordPress

Solicita

información

Page 9: Web Scrapping & WordPress

Solicita

información

Obtiene

información

Page 10: Web Scrapping & WordPress

Solicita

información

Obtiene

información

Filtra la

información

Page 11: Web Scrapping & WordPress

Solicita

información

Obtiene

información

Filtra la

información

Procesa la

información

Page 12: Web Scrapping & WordPress

Solicita

información

Obtiene

información

Filtra la

información

Procesa la

información

Guarda la

información

Page 13: Web Scrapping & WordPress

Solicita

información

Obtiene

información

Filtra la

información

Procesa la

información

Guarda la

información

Page 14: Web Scrapping & WordPress

PHP Simple HTML DOM Parser■ A HTML DOM parser written in PHP5+ let you manipulate

HTML in a very easy way!

■ Require PHP 5+.

■ Supports invalid HTML.

■ Find tags on an HTML page with selectors just like jQuery.

■ Extract contents from HTML in a single line.

http://simplehtmldom.sourceforge.net/

Page 15: Web Scrapping & WordPress

Ejemplo simple de cómo extraer usando PHP Simple HTML DOM Parser

<?php

// Create DOM from URL or file

$html = file_get_html('http://jovenred.

com/');

// Find all images foreach($html->find

('img') as $element) {

echo $element->src.'<br>';

}

// Find all links

foreach($html->find('a') as $element)

{

echo $element->href.'<br>';

}

?>

Page 16: Web Scrapping & WordPress

Tres formas para obtener un DOM Object

<?php

// Create a DOM object from a string

$html = str_get_html('<html><body>Hello!

</body></html>');

// Create a DOM object from a URL

$html = file_get_html('http://jovenred.

com/');

// Create a DOM object from a HTML file

$html = file_get_html('test.htm');

?>

Page 17: Web Scrapping & WordPress

Cómo buscar un elemento HTML

<?php

// Find all anchors, returns a array of

element objects

$ret = $html->find('a');

// Find (N)th anchor, returns element

object or null if not found (zero based)

$ret = $html->find('a', 0);

// Find all <div> with the id attribute

$ret = $html->find('div[id]');

// Find all <div> which attribute id=foo

$ret = $html->find('div[id=foo]');

?>

Page 18: Web Scrapping & WordPress

¿Y donde entraWordPress?

Page 19: Web Scrapping & WordPress

Solicita

información

Obtiene

información

Filtra la

información

Procesa la

información

Guarda la

información

Page 20: Web Scrapping & WordPress

Cómo ingresar la información a nuestra base de datos con WordPress

<?php

// Create DOM from URL or file

$html = file_get_html('http://jovenred.

com/');

// Find all images foreach($html->find('.

post') as $element) {

$title = $element->find('h2 a')-

>plaintext;

$content = $element->find('p', 0)-

>plaintext;

wp_insert_post( array(

'post_title' => $title;

'post_content' => $content;

) );

}

?>

Page 21: Web Scrapping & WordPress

Cómo ingresar la información a nuestra base de datos con WordPress

<?php

// Create DOM from URL or file

$html = file_get_html('http://jovenred.

com/');

// Find all images foreach($html->find('.

post') as $element) {

$title = $element->find('h2 a')-

>plaintext;

$content = $element->find('p', 0)-

>plaintext;

wp_insert_post( array(

'post_title' => $title;

'post_content' => $content;

) );

}

?>

Page 22: Web Scrapping & WordPress

#DataBomberosData Bomberos Perú es una página no oficial que muestra

información recolectada de la central de emergencias del Cuerpo

General de Bomberos Voluntarios del Perú.

La información es obtenida por la página Emergencias Diarias

que comparte el Cuerpo de Bomberos de forma pública en el

siguiente link http://www.bomberosperu.gob.pe/po_diario.asp.

http://databomberos.com

Page 23: Web Scrapping & WordPress

#DataBomberos

https://github.com/cesjam7/cbp-emergencies

Page 24: Web Scrapping & WordPress

#DataBomberos Emergencias del 14/05/2008

Emergencias por categoría Mapa de calor

Page 25: Web Scrapping & WordPress

Muchas gracias❏ Twitter: @cesjam7

❏ Blog: jovenred.com

❏ Empresa: orange612.com

❏ Presentaciones: speakerdeck.com/cesjam7

❏ Repositorios: github.com/cesjam7

Page 26: Web Scrapping & WordPress

Muchas gracias❏ Twitter: @cesjam7

❏ Blog: jovenred.com

❏ Empresa: orange612.com

❏ Presentaciones: speakerdeck.com/cesjam7

❏ Repositorios: github.com/cesjam7

Recuerden: En caso de emergencia llamar al 1-1-6