|
<?php |
|
include_once ("../lib/common.inc.php"); |
|
function fetchSON($SONID) |
|
{ |
|
global $conn; |
|
echo $SONID; |
|
|
|
# Create a search parser object |
|
$search = new DOMDocument(); |
|
$doc = 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.advancedsearch.CNSONRedirect&type=sonSearchEvent&SONID=$SONID")); |
|
|
|
# Iterate over all the <a> tags |
|
foreach ($search->getElementsByTagName('a') as $link) { |
|
# Show the <a href> |
|
if (strpos($link->getAttribute('href'), 'UUID')) { |
|
echo $link->getAttribute('href'); |
|
@$doc->loadHTML(file_get_contents("https://www.tenders.gov.au".$link->getAttribute('href'))); |
|
} |
|
} |
|
|
|
//TODO update title from $x("//p[@class='lead']/text()") |
|
|
|
|
|
$sql='insert into standingoffer_suppliers("SONID",name,abn,state,postcode) values(?,?,?,?,?)'; |
|
$q=$conn->prepare($sql); |
|
|
|
foreach($doc->getElementsByTagName('tr') as $row) { |
|
$supplier = Array("SONID"=>$SONID); |
|
$i = 0; |
|
foreach ($row->childNodes as $column){ |
|
//echo $i; |
|
if ($i==0) $supplier['name'] = $column->textContent; |
|
if ($i==2) $supplier['abn'] = trim(str_replace(' ','',$column->textContent)); |
|
if ($i==4) $supplier['state'] = $column->textContent; |
|
if ($i==6) $supplier['postcode'] = $column->textContent; |
|
//echo $column->textContent; |
|
$i++; |
|
} |
|
//print_r($supplier); |
|
$q->execute(array_values($supplier)); |
|
} |
|
} |
|
if ($_REQUEST['SONID']) { |
|
fetchSON($_REQUEST['SONID']); |
|
} |