3 ms·
Invoke-WebRequest most certainly runs on linux.
by vips7L 7y ago
Invoke-WebRequest most certainly runs on linux.
- dijit 7y agoI just attempted to prove you wrong, but it does look like it's fixed. So is creating secure strings. Cool!
- jodrellblank 7y agoCreating secure strings isn't exactly fixed; the type exists but they aren't encrypted in memory on Linux because it doesn't have the DPAPI (Data Protection API) from Windows: https://github.com/PowerShell/PowerShell/pull/9199 https://github.com/PowerShell/PowerShell/pull/9199
- danudey 7y agoThis comment made me go and try out Invoke-WebRequest because I'd forgotten what it was like. Being able to do simple web scraping like this in a "shell" is pretty great: $hn = Invoke-WebRequest https://news.ycombinator.com/ $hn.AllElements | Where {$_.TagName -eq "a" } | Where { $_.Class -eq "StoryLink" } | select "innerHtml"
- vips7L 7y agoIWR and ConvertFrom-Json are what got me hooked on powershell. No more learning complex switches for curl or crazy JQ syntax. It's all built in and makes sense.
- earthboundkid 7y agoFWIW, I already have a command line tool that can do that installed in regular Unix: https://github.com/ericchiang/pup https://github.com/ericchiang/pup The docs even use the same example of scraping HN. How does Invoke-WebRequest decide if it’s looking at HTML or something else?
- jve 7y agoWell, you use Invoke-RestMethod for JSON/XML stuff. Or decide yourself for Invoke-WebRequest to pipe it with whatever the data: ConvertFrom-{JSON,XML,CSV} With Invoke-WebRequest you get back headers, raw response, etc - and you get to decide whats next. With the RestMethod - just the content as an object.
- ct520 7y agoThere is an param to declare response type parsing and if you want to use different parsing. Older versions of powershell use IE and webrequest will randomly barf. It really sucked. You can also use a rest request method that uses json.net to deserialize I believe .