thelist.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /*
  3. * thelist web scraper for Land Title Details
  4. * Benjamin Harris, last updated 20/12/2021
  5. * https://sms.bisonconstructions.com.au
  6. */
  7. date_default_timezone_set("Australia/Hobart");
  8. error_reporting(E_ALL);
  9. ini_set('display_errors', 1);
  10. //error_reporting(E_ERROR | E_PARSE);
  11. // Function to perform a POST request for login
  12. function login($username, $password) {
  13. $loginUrl = 'https://security.thelist.tas.gov.au/cas/login'; // Updated login URL
  14. $loginData = array(
  15. 'username' => $username,
  16. 'password' => $password
  17. //'lt' => 'LT-2965-PYQs5SPwZuphpeuhmfQOwvHjfY3KQ6', // these are hidden inputs in the login form.
  18. //'execution' => 'e2s1',
  19. //'_eventId' => 'submit'
  20. );
  21. $ch = curl_init();
  22. curl_setopt($ch, CURLOPT_URL, $loginUrl);
  23. curl_setopt($ch, CURLOPT_POST, true);
  24. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($loginData));
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26. // Execute the login request
  27. $loginResponse = curl_exec($ch);
  28. // Check for errors and look for the success message
  29. if (curl_errno($ch)) {
  30. echo 'Error: ' . curl_error($ch);
  31. } elseif (strpos($loginResponse, '<div id="msg" class="success">') !== false) {
  32. echo 'Logged in successfully.';
  33. } else {
  34. echo 'Login failed.';
  35. }
  36. curl_close($ch);
  37. }
  38. // Function to scrape data from the search page
  39. function scrapeData($username, $password, $streetNumber, $streetName, $streetType, $locality) {
  40. // Call the login function to authenticate
  41. login($username, $password);
  42. // URL for the search with parameters
  43. $searchUrl = "https://www.thelist.tas.gov.au/app/content/property/property-search?streetNumber=$streetNumber&propertySearchCriteria.streetName=$streetName&propertySearchCriteria.streetType=$streetType&propertySearchCriteria.locality=$locality";
  44. $ch = curl_init();
  45. curl_setopt($ch, CURLOPT_URL, $searchUrl);
  46. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  47. // Execute the search request
  48. $searchResponse = curl_exec($ch);
  49. // Check for errors and parse the HTML response to extract the required data
  50. if (curl_errno($ch)) {
  51. echo 'Error: ' . curl_error($ch);
  52. } else {
  53. // Parse the HTML response and extract the required data
  54. $doc = new DOMDocument();
  55. @$doc->loadHTML($searchResponse); // Suppress errors for invalid HTML
  56. // Use XPath to extract specific elements
  57. $xpath = new DOMXPath($doc);
  58. $propertyListTitle = $xpath->query('//td[@aria-describedby="propertyList_title"]')->item(0)->textContent;
  59. $propertyListPropertyId = $xpath->query('//td[@aria-describedby="propertyList_propertyId"]')->item(0)->textContent;
  60. $propertyList1TName = $xpath->query('//td[@aria-describedby="propertyList_1_t_name"]')->item(0)->textContent;
  61. echo "propertyList_title: $propertyListTitle\n";
  62. echo "propertyList_propertyId: $propertyListPropertyId\n";
  63. echo "propertyList_1_t_name: $propertyList1TName\n";
  64. }
  65. curl_close($ch);
  66. }
  67. // Usage
  68. $username = 'david@bisonent.com.au';
  69. $password = 'takecare';
  70. $streetNumber = '29';
  71. $streetName = 'ALFRED';
  72. $streetType = 'ST';
  73. $locality = 'SCOTTSDALE';
  74. scrapeData($username, $password, $streetNumber, $streetName, $streetType, $locality);
  75. ?>