user206168
user206168

Reputation: 1025

Powershell Web Data Fetching

I am not sure what I am doing wrong. I am trying to fetch the data from URL below.

But I am not getting anything in return using the code below.

What I want to fetch (34)
enter image description here

Powershell Code

$downloadURL     = 'https://example.html'
$downloadRequest = Invoke-WebRequest -Uri $downloadURL

Result
Data not in the output code from Powershell

Upvotes: 0

Views: 210

Answers (1)

matt9
matt9

Reputation: 703

The page is dynamically created with JavaScript. It is hard to get the data by using Invoke-WebRequest cmdlet. Instead of that, try to use Internet Explorer COM object like this:

$url = 'https://example.com'
$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $false
$ie.Navigate2($url)
while($ie.ReadyState -ne 4) { Start-Sleep 1 }
$ie.document.body.getElementsByClassName('example-class-name')::outerHTML
$ie.document.body.getElementsByClassName('example-class-name')::textContent

For more information, see this article.

Upvotes: 1

Related Questions