Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ############################
- $logFile = "$env:USERPROFILEdesktopISOCountry.log"
- Start-Transcript -Path $logFile -Append
- #########################################
- $WebResponse = Invoke-WebRequest "http://kirste.userpage.fu-berlin.de/diverse/doc/ISO_3166.html"
- #$WebResponse = Invoke-WebRequest "https://en.wikipedia.org/wiki/ISO_3166-1"
- $PRETAG = $WebResponse.ParsedHtml.getElementsByTagName("PRE") | select -expand innertext
- $PRETAG
- $JsonText = $PRETAG | ConvertTo-csv
- $JsonText
- # end logging
- ###########################
- Stop-Transcript
- ###########################
- $URI = “https://en.wikipedia.org/wiki/ISO_3166-1“
- $HTML = Invoke-WebRequest -Uri $URI
- ($HTML.ParsedHtml.getElementsByTagName('table') | Where{ $_.className -eq 'wikitable sortable' }).innerText
- cls
- [void][Reflection.Assembly]::LoadFile("C:tempHtmlAgilityPacklibNet20HtmlAgilityPack.dll”)
- [HtmlAgilityPack.HtmlWeb]$web = @{}
- [HtmlAgilityPack.HtmlDocument]$doc = $web.Load("https://en.wikipedia.org/wiki/ISO_3166-1")
- ## FILTER NEEDED CONTENT THROUGH X-PATH
- [HtmlAgilityPack.HtmlNodeCollection]$country = $doc.DocumentNode.SelectNodes("//table[2]//tr//td[1]")
- [HtmlAgilityPack.HtmlNodeCollection]$iso = $doc.DocumentNode.SelectNodes("//table[2]//tr//td[5]")
- ## Create temp arry
- $arr = @()
- $arr += [pscustomobject] @{
- country = $country.InnerText
- iso = $iso.innertext
- }
- # go trough the arrays and put each item into output
- $output = @()
- for($i=0; $i -le $arr.country.Length; $i++){
- $output += [pscustomobject] @{
- country = $arr.Country[$i]
- iso = $arr.Iso[$i]
- }
- }
- # export csv
- $output | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | out-file C:tempiso.csv -Force
- "country";"iso"
- "Afghanistan";"ISO 3166-2:AF"
- "Aland Islands !Åland Islands";"ISO 3166-2:AX"
- "Albania";"ISO 3166-2:AL"
- "Algeria";"ISO 3166-2:DZ"
- "American Samoa";"ISO 3166-2:AS"
Add Comment
Please, Sign In to add comment