parse worlometers

This commit is contained in:
Göran Heinemann 2020-03-06 09:08:18 +01:00
parent e227697c7c
commit 414a17a6ff
2 changed files with 29 additions and 1 deletions

View File

@ -8,5 +8,29 @@ $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($data as $scan){
$document = new DOMDocument();
$document->loadHTML($scan['content']);
var_dump($document);
$table = $document->getElementById("main_table_countries_div");
$table = $table->childNodes[1];
$data = $table->childNodes[1];
$parts = $data->childNodes;
$document = array();
for ($i = 0; $i < $parts->length; $i++) {
$country = array();
$p2 = $parts[$i]->childNodes;
$country[] = $p2[0]->textContent;
$country[] = $p2[2]->textContent;
$document[] = $country;
}
$scanid = $scan['id'];
foreach ($document as $entry){
$sql = "INSERT INTO `data`(`scan`, `place`, `amount`) VALUES (?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $scanid);
$stmt->bindParam(2, $entry[0]);
$stmt->bindParam(3, $entry[1]);
$stmt->execute();
if($stmt->errorInfo()[0] != '00000' and $stmt->errorInfo()[0] != '23000' and $stmt->errorInfo()[0] != '22007')
var_dump($stmt->errorInfo());
}
}

4
parse.php Normal file
View File

@ -0,0 +1,4 @@
#! /usr/bin/php
<?php
include 'parse-rki.php';
include 'parse-worldometers.php';