$username,
'password' => $password
//'lt' => 'LT-2965-PYQs5SPwZuphpeuhmfQOwvHjfY3KQ6', // these are hidden inputs in the login form.
//'execution' => 'e2s1',
//'_eventId' => 'submit'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($loginData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the login request
$loginResponse = curl_exec($ch);
// Check for errors and look for the success message
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} elseif (strpos($loginResponse, '
') !== false) {
echo 'Logged in successfully.';
} else {
echo 'Login failed.';
}
curl_close($ch);
}
// Function to scrape data from the search page
function scrapeData($username, $password, $streetNumber, $streetName, $streetType, $locality) {
// Call the login function to authenticate
login($username, $password);
// URL for the search with parameters
$searchUrl = "https://www.thelist.tas.gov.au/app/content/property/property-search?streetNumber=$streetNumber&propertySearchCriteria.streetName=$streetName&propertySearchCriteria.streetType=$streetType&propertySearchCriteria.locality=$locality";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $searchUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the search request
$searchResponse = curl_exec($ch);
// Check for errors and parse the HTML response to extract the required data
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} else {
// Parse the HTML response and extract the required data
$doc = new DOMDocument();
@$doc->loadHTML($searchResponse); // Suppress errors for invalid HTML
// Use XPath to extract specific elements
$xpath = new DOMXPath($doc);
$propertyListTitle = $xpath->query('//td[@aria-describedby="propertyList_title"]')->item(0)->textContent;
$propertyListPropertyId = $xpath->query('//td[@aria-describedby="propertyList_propertyId"]')->item(0)->textContent;
$propertyList1TName = $xpath->query('//td[@aria-describedby="propertyList_1_t_name"]')->item(0)->textContent;
echo "propertyList_title: $propertyListTitle\n";
echo "propertyList_propertyId: $propertyListPropertyId\n";
echo "propertyList_1_t_name: $propertyList1TName\n";
}
curl_close($ch);
}
// Usage
$username = 'david@bisonent.com.au';
$password = 'takecare';
$streetNumber = '29';
$streetName = 'ALFRED';
$streetType = 'ST';
$locality = 'SCOTTSDALE';
scrapeData($username, $password, $streetNumber, $streetName, $streetType, $locality);
?>