Calcetines Extreme

Calcetines Extreme
Take care of you using the best socks

Tuesday, October 27, 2020

How to scrap elements from external website

Problem:

You need to pic information from a public website and process it internally to do some staff.

Solution:

You can use PHP Simple HTML DOM parse as the easy way, follow the next steps:

  1. Download the sources from the oficial web site
  2. copy all files into your web server
  3. create a new file example.php
  4. use this code:

include_once('simple_html_dom.php');

$context = stream_context_create();

stream_context_set_params($context, array(

            'ignore_errors' => true, 

            'max_redirects' => 3)

            );

$html = file_get_html('https://www.elmundo.es', 0, $context);

$articles_titles = $html->find(".ue-c-cover-content__link");

foreach($articles_titles as $article_title) {

    echo "<BR>\t\t".$article_title->plaintext."\n";

}

$html->clear();

unset($html);

echo "<BR>";echo "<BR>";echo "<BR>";

echo "<BR>OK";

Information That's it, now you only need to analyse the information that you get as html and process it in your function or program, take care about your objective, the server that you use to extract the information can ban your IP; to avoid that it's possible to use a proxy as is indicated int he source link.

Source:

https://www.fernandezsansalvador.es/hacer-web-scraping-con-php-simple-html-dom-parser/