Download html content and save to BD [closed]

2

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

Thanks

    
asked by Fabiola Cendales 25.05.2017 в 06:56
source

1 answer

1

To download the html content:

/* Para no limitar el tiempo de ejecución, se puede demorar */
set_time_limit(0);

$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);
fclose($handlerFileCSV);

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

    mysql -vvvvv -u admin -pJl@2016.. -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.

Greetings,

    
answered by 25.05.2017 / 07:11
source