category breakdown
[contractdashboard.git] / admin / downloadExports.php
blob:a/admin/downloadExports.php -> blob:b/admin/downloadExports.php
--- a/admin/downloadExports.php
+++ b/admin/downloadExports.php
@@ -1,1 +1,28 @@
+<?php
+# Create a search parser object
+$search = new DOMDocument();
 
+# Parse the HTML from Google.
+# The @ before the method call suppresses any warnings that
+# loadHTML might throw because of invalid HTML in the page.
+@$search->loadHTML(file_get_contents("https://www.tenders.gov.au/?event=public.reports.listCNWeeklyExport"));
+
+$xpath = new DOMXPath($search);
+$ls_ads = $xpath->query('//div[@class=\'list-datalist\']');
+foreach ($ls_ads as $ad) {
+# Iterate over all the <a> tags
+    $i=0;
+    foreach ($ad->getElementsByTagName('a') as $link) {
+        # Show the <a href>
+        if (strpos($link->getAttribute('href'), 'UUID') && $i < 4) {
+            echo $link->getAttribute('href')."\n";
+            //@$doc->loadHTML()));
+            $myfile = fopen("data/AustenderExport-".$link->textContent.".xls", "w") or die("Unable to open file!");
+            fwrite($myfile, file_get_contents("https://www.tenders.gov.au" . $link->getAttribute('href')));
+            fclose($myfile);
+            $i++;
+        }
+
+    }
+}
+