Powershell - 使用 JS 从门户网站自动下载 CSV

问题描述

我正在编写一个脚本,用于从 Autodesk 门户自动下载 CSV 报告。我尝试了 Invoke-WebRequest cmdlet 和 IE COM Object 来请求站点,然后提交我的用户名和密码。

问题是,一旦我到达包含复选框和列表框的页面,该特定页面就会使用大量 javascript 来加载页面,因此当我执行 Invoke-Webrequest 时,原始内容只是一个空的 html 正文。

有什么方法可以访问 Javascript 函数,以便我可以操作这些字段?

[![函数示例][1]][1]

代码 1

$autodesk = Invoke-WebRequest 'https://manage.autodesk.com/all-account-export' -SessionVariable sbv 
$webForm = $autodesk.Forms[0]
$webForm.Fields["userName"]="Username"
$webForm.Fields["password"]="Password"
$r = Invoke-WebRequest -Uri ('https://accounts.autodesk.com' + $webForm.Action) -WebSession $sbv -Method POST -Body $webForm.Fields

代码 2

$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible

$username="Username"

$password="Password"

$ie.Navigate("https://manage.autodesk.com/all-account-export")

While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}

$usernamefield = $ie.document.getElementByID('userName')
$usernamefield.value = "$username"

$passwordfield = $ie.document.getElementByID('password')
$passwordfield.value = "$password"

$Link = $ie.document.getElementByID('btnSubmit')
$Link.click()


  [1]: https://i.stack.imgur.com/3jfeu.png

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)