Forum Discussion

AlexanderHolmeset's avatar
Jul 13, 2017
Solved

Catch dates from website

I got this from someone, and for Albania it works like it should. But if i change to for example Germany as country, it gets text and not the correct dates in the date collum.  I see that with German...
  •  Try below script and it will work more most country Like USA,INDIA,germany but it will not work for albania.

     

    $uri = 'http://www.officeholidays.com/countries/usa/index.php'
    $html = Invoke-WebRequest -Uri $uri
    $tables = $html.ParsedHtml.getElementsByTagName('tr') |
    Where-Object {$_.classname -eq 'holiday' -or $_.classname -eq 'regional' } |
    Select-Object -exp innerHTML
    foreach ($table In $tables){ 
    $day= (($table -split "<TD>")[1] -split "</TD>")[0] ;
    
    $Date = (($table -split "<SPAN class=ad_head_728>")[1] -split "</SPAN>")[0]; 
    
    $Holiday = ((($table -split "<TD><A title=")[1] -split ">")[1] -split "</A")[0]
    $Remarks = (($table -split "class=remarks>")[1] -split "<")[0]; 
    [PSCustomObject]@{
            Date = $Date  ; Holiday = $Holiday
            Remarks = If ($Holiday -ne $Remarks){$Remarks}}
    
     }

Resources