1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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++; } } } |