David Metcalfe
David Metcalfe

Reputation: 2411

Get full URL in Powershell Invoke-WebRequest Links

I'm currently pulling all links from a webpage of choice, but the extracted URLs don't contain the full address, and instead, look like /example/somepage instead of http://baseURL/example/somepage.

Can I output the full address somehow, or do I have to concatenate the two strings?

The code used is below.

$url = 'http://baseURL'
$request = Invoke-WebRequest –Uri $url
$request.Links | select href

Upvotes: 1

Views: 4572

Answers (1)

Nas
Nas

Reputation: 1263

$url = 'http://baseURL'
$request = Invoke-WebRequest –Uri $url
$request.Links | Select-Object @{Label='href';Expression={@{$true=$_.href;$false=$url+$_.href}[$_.href.StartsWith('http')]}}

Upvotes: 3

Related Questions