thelist.php 3.3 KB

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