Guest User

Untitled

a guest
Nov 20th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. # ############################
  2. $logFile = "$env:USERPROFILEdesktopISOCountry.log"
  3. Start-Transcript -Path $logFile -Append
  4. #########################################
  5.  
  6. $WebResponse = Invoke-WebRequest "http://kirste.userpage.fu-berlin.de/diverse/doc/ISO_3166.html"
  7. #$WebResponse = Invoke-WebRequest "https://en.wikipedia.org/wiki/ISO_3166-1"
  8. $PRETAG = $WebResponse.ParsedHtml.getElementsByTagName("PRE") | select -expand innertext
  9. $PRETAG
  10. $JsonText = $PRETAG | ConvertTo-csv
  11. $JsonText
  12. # end logging
  13. ###########################
  14. Stop-Transcript
  15. ###########################
  16.  
  17. $URI = “https://en.wikipedia.org/wiki/ISO_3166-1“
  18. $HTML = Invoke-WebRequest -Uri $URI
  19. ($HTML.ParsedHtml.getElementsByTagName('table') | Where{ $_.className -eq 'wikitable sortable' }).innerText
  20.  
  21. cls
  22. [void][Reflection.Assembly]::LoadFile("C:tempHtmlAgilityPacklibNet20HtmlAgilityPack.dll”)
  23. [HtmlAgilityPack.HtmlWeb]$web = @{}
  24. [HtmlAgilityPack.HtmlDocument]$doc = $web.Load("https://en.wikipedia.org/wiki/ISO_3166-1")
  25.  
  26. ## FILTER NEEDED CONTENT THROUGH X-PATH
  27. [HtmlAgilityPack.HtmlNodeCollection]$country = $doc.DocumentNode.SelectNodes("//table[2]//tr//td[1]")
  28. [HtmlAgilityPack.HtmlNodeCollection]$iso = $doc.DocumentNode.SelectNodes("//table[2]//tr//td[5]")
  29.  
  30. ## Create temp arry
  31. $arr = @()
  32. $arr += [pscustomobject] @{
  33. country = $country.InnerText
  34. iso = $iso.innertext
  35. }
  36.  
  37. # go trough the arrays and put each item into output
  38. $output = @()
  39. for($i=0; $i -le $arr.country.Length; $i++){
  40.  
  41. $output += [pscustomobject] @{
  42. country = $arr.Country[$i]
  43. iso = $arr.Iso[$i]
  44. }
  45.  
  46. }
  47. # export csv
  48. $output | ConvertTo-Csv -Delimiter ";" -NoTypeInformation | out-file C:tempiso.csv -Force
  49.  
  50. "country";"iso"
  51. "Afghanistan";"ISO 3166-2:AF"
  52. "Aland Islands !Åland Islands";"ISO 3166-2:AX"
  53. "Albania";"ISO 3166-2:AL"
  54. "Algeria";"ISO 3166-2:DZ"
  55. "American Samoa";"ISO 3166-2:AS"
Add Comment
Please, Sign In to add comment