【问题标题】:HTTP File Upload via Powershell通过 Powershell 上传 HTTP 文件
【发布时间】:2019-11-20 15:08:39
【问题描述】:

我尝试在 Fritz!Box 上通过 powershell 自动上传文件,但它不起作用。 我通过 Internet Explorer 登录。

$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$true
$ie.Navigate("192.168.178.1/")
do {sleep 1} until (-not ($ie.Busy))
$ie.document.getElementById("uiPass").value = "pass"
$ie.Document.getElementById("submitLoginBtn").click()
do {sleep 1} until (-not ($ie.Busy)) 
$ie.Document.getElementsByTagName['uiImport'].value=Get-Content "myfile" -Raw

我的问题是,我真的不明白 uiImport 的属性是什么。这是我的文件应该以表格形式上传的地方,但 Powershell 一直说它找不到这个属性。

【问题讨论】:

    标签: powershell http internet-explorer


    【解决方案1】:

    $ie.Document.getElementsByTagName['uiImport'].value=获取内容 “我的文件”-原始

    请尝试使用F12开发者工具检查网页资源,页面是否包含“uiImport”自定义标签。

    从我的角度来看,我认为也许“uiImport”是输入元素的Name属性,而不是标签名称。如果是这种情况,您可以使用 Document.getElementsByName() 方法来查找输入文本。然后,设置值。

    示例代码如下:

    $ie = New-Object -com InternetExplorer.Application 
    $ie.visible=$true
    $ie.Navigate("<web page url>")
    do {sleep 1} until (-not ($ie.Busy))
    
    $elements = $ie.document.getElementsByName("files")
    $elements[0].value ="file path"
    

    网页资源:

    Upload file : <input type="text" id="txtupload" name="files" class="file"  value=""/><br />
    
    Download file : <input type="text" id="txtdownload" name="files" class="file" value=""/>
    

    在上面的示例中,我使用索引来查找特殊的上传文本,您也可以使用 where 子句或使用 Document.getElementById() 方法来查找文本框。代码如下:

    $uploadtext = $ie.document.getElementsByName("files") | ?{ $_.Id -eq 'txtupload'}
    $uploadtext.value ="hello world"
    $downloadtext = $ie.document.getElementsByName("files") | where{ $_.Id -eq 'txtdownload'}
    $downloadtext.value ="hi"
    

    【讨论】:

      猜你喜欢
      • 2016-11-05
      • 2011-03-20
      • 2010-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 2010-12-24
      相关资源
      最近更新 更多