Download html content and save to BD [closed]


I need a script that connects to an auction site, downloads them and stores them in a database.

This is an example of the information that appears

Auction: xxxxxxxxx

Value Offered: xxxxxxxxxxx

Good: xxxxxxxxxxxx

They could help me with a guide to do it in PHP


asked by Fabiola Cendales 25.05.2017 в 06:56

1 answer


To download the html content:

/* Para no limitar el tiempo de ejecución, se puede demorar */

$url = "http://urldelsitio"; 
$html = file_get_contents($url);
$html = fix($html);
$fileName = fileSave("bienes", $html);
$file = fopen($fileName, "r");

Then you iterate the file locating the blocks:

$strContent = "";
$strFile = "";
while (($line_detail = fgets($file)) !== false) {
    if (strpos($line_detail, "Subasta:") !== FALSE) {
         $strContent .= str_replace("Subasta:", "", line_detail) . ";";

    /*.... Lo haces para cada linea ..... */

   if (strpos($line_detail, "Bien:") !== FALSE) {
       $strContent .= str_replace("Subasta:", "", line_detail) . ";";
       $strFile .= $strContent . "\n";
       $strContent = "";

    /* al final obtienes la linea separada por comas  y así armas el csv */

/* Guardas el archivo */
$handlerFileCSV = fopen("file.csv", "a");
fwrite($handlerFileCSV, $strFile);

    /* Finalmente Importas el archivo a la BD, en la consola de linux o con un batch */

    mysql -vvvvv -u admin [email protected] -h localhost -e "LOAD DATA INFILE '/var/lib/mysql-files/$4' INTO TABLE <tabla> FIELDS TERMINATED BY ';' (<field1, field2, field3, ...>);" <base de datos>

This is an idea of how you can do it, you will understand that it takes time to finish it.


answered by 25.05.2017 / 07:11