|
16th September 2019, 16:52 | #1 |
Stuff
|
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.
__________________
My degree of sarcasm depends on your degree of stupidity. Last edited by MadMax : 16th September 2019 at 16:57. |
16th September 2019, 18:12 | #2 |
|
https://sharepoint.fpweb.net/sharepo...ith-csv-files/
has exactly what you're after. I googled for "powershell csv file"
__________________
Ξ √ Ω L U T ↑ ☼ N وكل يوم كنت تعيش في العبودية |
16th September 2019, 18:14 | #3 |
|
Or a slightly different way of doing the same:
https://stackoverflow.com/questions/...esponding-data
__________________
Ξ √ Ω L U T ↑ ☼ N وكل يوم كنت تعيش في العبودية |
16th September 2019, 20:01 | #4 |
Stuff
|
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
__________________
My degree of sarcasm depends on your degree of stupidity. Last edited by MadMax : 16th September 2019 at 20:02. |
16th September 2019, 20:17 | #5 |
Stuff
|
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]
__________________
My degree of sarcasm depends on your degree of stupidity. |
16th September 2019, 20:35 | #6 |
Stuff
|
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
__________________
My degree of sarcasm depends on your degree of stupidity. |
16th September 2019, 21:22 | #7 |
|
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.
__________________
Ξ √ Ω L U T ↑ ☼ N وكل يوم كنت تعيش في العبودية |
17th September 2019, 10:59 | #8 | |
|
Quote:
|
|