0

Im atempting to parse a webrequest. What is best way? Get the variable to a String array or Object array?
The webrequest supplies a string object, but I can't split by line because some lines are multiple.. Would comma delimit be best bet? Im having difficulty and running out of ideas.

    $webresponse = (invoke-webrequest -Uri "https://docs.google.com/spreadsheets/d/e/2PACX-1vR99VhhEfs2VKo3FWuTqC66vEzlmiqAODGiAaicmswvyf3PdtOX2YYoP72ou52CdUpgqEbr9OAK6X0x/pub?output=csv").content

If I split by comma

$webresponse.Split(",")

I can get it into a string array, but then not sure on next step OR even if this is most efficient way through this task. Any help would be greatly appreciated Thanks in advance

1 Answer 1

4

The response is CSV, as the URL indicates with the output=csv parameter.

Use the ConvertFrom-Csv cmdlet.

$webresponse = Invoke-Webrequest -Uri "https://docs.google.com/spreadsheets/d/e/2PACX-1vR99VhhEfs2VKo3FWuTqC66vEzlmiqAODGiAaicmswvyf3PdtOX2YYoP72ou52CdUpgqEbr9OAK6X0x/pub?output=csv"
$data = $webresponse.Content | ConvertFrom-Csv -Delimiter ","

$data will be an array.

$data.Count
# 175

PowerShell will assume the CSV has headers by default, which conveniently is the case here.

$data[0]
# Tweet                                       DateTime                   
# -----                                       --------                 
# SPOT PLATINUM FALLS OVER 5% TO $1,007.20/OZ January 11, 2021 at 08:25AM

$data[0].Tweet
# SPOT PLATINUM FALLS OVER 5% TO $1,007.20/OZ
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.