Phylum

Scraper Attempt #1

Sep 17th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Site to grab
  2. $URL = 'http://www.bww-law.com/sales.asp'
  3.  
  4. # Grab content
  5. $Result = Invoke-WebRequest $URL
  6.  
  7. # Collection to hold the bits
  8. [System.Collections.ArrayList]$Properties = @{}
  9.  
  10. # Loop through array to [hopefully] grab the
  11. for($i=0; $i -lt $Result.AllElements.Count; $i++)
  12.     {
  13.         write-host "i [$i]"
  14.         if(!$Result.AllElements[$i].Class) { continue }
  15.         if([string]::IsNullOrEmpty($Result.AllElements[$i])) { continue }
  16.         if([string]::IsNullOrEmpty($Result.AllElements[$i].innerText)) { continue }
  17.         if([string]::IsNullOrEmpty($($Result.AllElements[$i] | select -ExpandProperty innerText))) { continue }
  18.         if([string]::IsNullOrEmpty($($Result.AllElements[$i] | select -ExpandProperty innerText))) { continue }
  19.         if($($Result.AllElements[$i] | select -ExpandProperty innerHTML).Trim() -like '&nbsp*') { continue }
  20.         if($($Result.AllElements[$i] | select -ExpandProperty innerHTML).Trim() -like '<!--*') { continue }
  21.         if($($Result.AllElements[$i] | select -ExpandProperty innerHTML).Trim() -like '<A href="#*') { continue }
  22.         if($($Result.AllElements[$i] | select -ExpandProperty innerText).Trim() -eq 'Virginia Sales') { continue }
  23.         if($($Result.AllElements[$i] | select -ExpandProperty innerText).Trim() -like '*All sales in Virginia are conducted*') { continue }
  24.         if(($Result.AllElements[$i] | select -ExpandProperty innerText) -like 'Jurisdiction') { continue }
  25.         if(($Result.AllElements[$i] | select -ExpandProperty innerText) -like 'File #') { continue }
  26.         if(($Result.AllElements[$i] | select -ExpandProperty innerText) -like 'Sale Date') { continue }
  27.         if(($Result.AllElements[$i] | select -ExpandProperty innerText) -like 'Sale Time') { continue }
  28.         if(($Result.AllElements[$i] | select -ExpandProperty innerText) -like 'Property Address') { continue }
  29.         if(($Result.AllElements[$i] | select -ExpandProperty innerText) -like 'City') { continue }
  30.         if(($Result.AllElements[$i] | select -ExpandProperty innerText) -like 'Zip') { continue }
  31.         if(($Result.AllElements[$i] | select -ExpandProperty innerText) -like '*Loan Amount*') { continue }
  32.  
  33.  
  34.         $Class = $Result.AllElements[$i].Class
  35.         write-host "Class [$Class]"
  36.  
  37.         $CityCounty  = $Result.AllElements[$i] | select -ExpandProperty innerText
  38.         write-host "CityCounty [$CityCounty]"
  39.  
  40.         $JurisdictionFileNumber = $Result.AllElements[$i+4] | select -ExpandProperty innerText
  41.         write-host "JurisdictionFileNumber [$JurisdictionFileNumber]"
  42.  
  43.         $SaleDate = $Result.AllElements[$i+5] | select -ExpandProperty innerText
  44.         write-host "SaleDate [$SaleDate]"
  45.  
  46.         $SaleTime = $Result.AllElements[$i+6] | select -ExpandProperty innerText
  47.         write-host "SaleTime [$SaleTime]"
  48.  
  49.         $PropertyAddress = $Result.AllElements[$i+7] | select -ExpandProperty innerText
  50.         write-host "PropertyAddress [$PropertyAddress]"
  51.  
  52.         $City = $Result.AllElements[$i+8] | select -ExpandProperty innerText
  53.         write-host "City [$City]"
  54.  
  55.         $Zip = $Result.AllElements[$i+9] | select -ExpandProperty innerText
  56.         write-host "Zip [$Zip]"
  57.  
  58.         $OriginalLoanAmount = $Result.AllElements[$i+10] | select -ExpandProperty innerText
  59.         write-host "OriginalLoanAmount [$OriginalLoanAmount]"
  60.        
  61.         $Properties += [pscustomobject]@{CityCounty = $CityCounty;
  62.             JurisdictionFileNumber = $JurisdictionFileNumber;
  63.             SaleDate = $SaleDate;
  64.             SaleTime = $SaleTime;
  65.             PropertyAddress = $PropertyAddress;
  66.             City = $City;
  67.             Zip = $Zip;
  68.             OriginalLoanAmount = $OriginalLoanAmount;
  69.             MapLink = "https://maps.google.com/maps?q=$($PropertyAddress.Replace(' ','+'))+$City+VA+$Zip"
  70.             SearchLink = "https://google.com/search?q=$($PropertyAddress.Replace(' ','+'))+$City+VA+$Zip"
  71.         }
  72.  
  73.         Remove-Variable Class,CityCounty,JurisdictionFileNumber,SaleDate,SaleTime,PropertyAddress,City,Zip,OriginalLoanAmount -ErrorAction SilentlyContinue
  74.         break
  75.     }
Advertisement
Add Comment
Please, Sign In to add comment