Display all content with Invoke-WebRequest

后端 未结 3 907
抹茶落季
抹茶落季 2021-02-05 01:54

So I decided to start using PowerShell rather than Command Prompt. And I want to run curl. Very different output then discover that curl is an alias to

相关标签:
3条回答
  • 2021-02-05 02:20

    Something like this?

    $res=Invoke-WebRequest "https://www.google.fr/" 
    
    
    #for look html of body
    $res.ParsedHtml.body.innerHTML
    
    #for look text of body
    $res.ParsedHtml.body.innerText
    
    0 讨论(0)
  • 2021-02-05 02:24

    Well, if you are bothered with extra typing this is the shortest way to achieve that (well, at least I can think of):

    (iwr google.tt).content
    
    0 讨论(0)
  • 2021-02-05 02:25

    Unlike the curl command line utility Invoke-WebRequest returns an object with various properties of which the content of the requested document is just one. You can get the content in a single statement by expanding the property like this:

    Invoke-WebRequest 'http://www.example.org/' | Select-Object -Expand Content
    

    or by getting the property value via dot-notation like this:

    (Invoke-WebRequest 'http://www.example.org/').Content
    

    Alternatively you could use the Windows port of curl:

    & curl.exe 'http://www.example.org/'
    

    Call the program with its extension to distinguish it from the alias curl for Invoke-WebRequest.

    0 讨论(0)
提交回复
热议问题