NZGames.com Forums

NZGames.com Forums (https://forums.nzgames.com/index.php)
-   Technology & Troubleshooting (https://forums.nzgames.com/forumdisplay.php?f=9)
-   -   powershell - website scraping (https://forums.nzgames.com/showthread.php?t=87910)

MadMax 16th September 2019 16:52

powershell - website scraping
 
If I run the following:


$nzpost = invoke-webrequest -uri https://nzpost.co.nz/tools/address-p...inder/address/[somenumber]/1 long street highbury palmerston north rd1
($nzpost.inputfields.value -split '\n')[1]


... i get the resolved address including the postcode (assuming a valid address).

If i had a csv file like the following:
address1, address2, city, rural
1 long street, highbury, palmerston north, rd1
1 short road, awapuni, palmerston north, rd1

(eg, $csvfile = import-csv -path 'c:\addresses.csv'

How would i do a scrape for-each of the csv file lines?

[somenumber] seems to be a static random that's re-usable.

crocos 16th September 2019 18:12

https://sharepoint.fpweb.net/sharepo...ith-csv-files/

has exactly what you're after. I googled for "powershell csv file"

crocos 16th September 2019 18:14

Or a slightly different way of doing the same:
https://stackoverflow.com/questions/...esponding-data

MadMax 16th September 2019 20:01

I'm ok with the handling of the csv file (i believe), just not the syntax on how to call the invoke-webrequest of the for-each.

for example

Import-Csv -Path 'C:\file.csv' | foreach {
-join ($_.Address3,' ', $_.Suburb,' ',$_.Town,' ',$_.Rural )
}

outputs the query i want and i want to run that against
invoke-webrequest -uri https://www.nzpost.co.nz/tools/addre...inder/address/[number]/[{(join query here)}]

I'm trying to work out that [{( bit

MadMax 16th September 2019 20:17

right, so:

$query = invoke-webrequest -uri "https://www.nzpost.co.nz/tools/address-postcode-finder/address/[number]/1 long street palmerston north"
($query.inputfields.value -split '\n')[1]

can be changed to:

((invoke-webrequest -uri "https://www.nzpost.co.nz/tools/address-postcode-finder/address/[number]/1 long street palmerston north").inputfields.value -split '\n')[1]

MadMax 16th September 2019 20:35

so i got the query working but turns out that number isn't static and is based on the address.

poo.

https://www.nzpost.co.nz/tools/addre...inder/address/[number]1 crater lake the moon

will always return the same result based on the number :(

crocos 16th September 2019 21:22

You'll need to register for NZPost's API service

https://www.nzpost.co.nz/business/developer-centre

For non commercial it may even be free, I don't know.

blynk 17th September 2019 10:59

Quote:

Originally Posted by MadMax (Post 2008450)
so i got the query working but turns out that number isn't static and is based on the address.

poo.

https://www.nzpost.co.nz/tools/addre...inder/address/[number]1 crater lake the moon

will always return the same result based on the number :(

I was going to say I was surprised you could just scrap that.


All times are GMT +13. The time now is 17:30.

Powered by Trololololooooo
© Copyright NZGames.com 1996-2024
Site paid for by members (love you guys)