Created
July 21, 2020 19:32
-
-
Save MateuszNad/6af91ed3eb4ba51fc7551432b7db99e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-OtodomSprzedaz | |
{ | |
#Requires -Version 3.0 | |
param( | |
[Parameter(Mandatory)] | |
[String[]]$Url | |
) | |
begin | |
{ | |
$regex = '\d+' | |
} | |
process | |
{ | |
foreach ($ItemUrl in $Url) | |
{ | |
$ContentWebsite = Invoke-WebRequest -Uri $ItemUrl | |
$DivElements = ($ContentWebsite.ParsedHtml).getElementsByTagName('div') | |
# pobranie sekcji z detalami oferty | |
$ClassElements = $DivElements | Where-Object className -EQ 'offer-item-details' | |
foreach ($ClassElement in $ClassElements) | |
{ | |
$OfferDetails = ($ClassElement.getElementsByTagName('li') | Select-Object innerText).innerText -split '[\n]' | |
$OfferObject = [PSCustomObject]@{ | |
Lokalizacja = (($ClassElement.getElementsByTagName('p') | Select-Object innerText).innerText).Replace('Mieszkanie na sprzedaż: ', '') | |
Pokoje = [int]([regex]::Match($OfferDetails[0].Replace(' ', ''), $regex).Value) | |
Cena = [int]([regex]::Match($OfferDetails[1].Replace(' ', ''), $regex).Value) | |
Powierzchnia = [int]([regex]::Match($OfferDetails[2].Replace(' ', ''), $regex).Value) | |
CenaPerMetr = [int]([regex]::Match($OfferDetails[3].Replace(' ', ''), $regex).Value) | |
Link = ($ClassElement.getElementsByTagName('a') | Select-Object href)[0].href | |
} | |
Write-Output $OfferObject | |
} | |
} | |
} | |
} | |
$Url = 'https://www.otodom.pl/sprzedaz/mieszkanie/poznan/?search%5Bregion_id%5D=15&search%5Bsubregion_id%5D=462&search%5Bcity_id%5D=1&nrAdsPerPage=72' | |
Get-OtodomSprzedaz -Url $Url | Format-Table -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment