From 414a17a6ff79f37537a7b8848a6cc9b05c17e2d0 Mon Sep 17 00:00:00 2001 From: Goeran Heinemann Date: Fri, 6 Mar 2020 09:08:18 +0100 Subject: [PATCH] parse worlometers --- parse-worldometers.php | 26 +++++++++++++++++++++++++- parse.php | 4 ++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 parse.php diff --git a/parse-worldometers.php b/parse-worldometers.php index 9f3c2d5..8b6bc49 100755 --- a/parse-worldometers.php +++ b/parse-worldometers.php @@ -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()); + } } \ No newline at end of file diff --git a/parse.php b/parse.php new file mode 100644 index 0000000..e8d8e3c --- /dev/null +++ b/parse.php @@ -0,0 +1,4 @@ +#! /usr/bin/php +