代码之家  ›  专栏  ›  技术社区  ›  user206168

Powershell Web数据获取

  •  0
  • user206168  · 技术社区  · 8 年前

    我不确定我做错了什么。我正在尝试从下面的URL获取数据。

    我要拿的东西 (34)
    enter image description here

    Powershell代码

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


    数据不在Powershell的输出代码中

    1 回复  |  直到 8 年前
        1
  •  1
  •   matt9    8 年前

    该页面是使用JavaScript动态创建的。很难使用 Invoke-WebRequest cmdlet。相反,请尝试使用Internet Explorer COM对象,如下所示:

    $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
    

    有关更多信息,请参阅 this article .