powershell - 通过 Powershell 上传 HTTP 文件
问题描述
我尝试通过 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 一直说它找不到这个属性。
解决方案
$ie.Document.getElementsByTagName['uiImport'].value=Get-Content "myfile" -Raw
请尝试使用F12开发者工具检查网页资源,页面是否包含“uiImport”自定义标签。
从我的角度来看,我认为也许“uiImport”是输入元素的名称属性,而不是标签名称。如果是这种情况,您可以使用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"
推荐阅读
- sqlalchemy - 在审计表中添加 JSON 数据
- performance - Elasticsearch 随着大小参数的增加变慢(不依赖于数据大小)
- vowpalwabbit - `vw --audit` 如何在内部计算特征的权重?
- hugo - 如何使用 netlify CMS 在博客部分添加博客文章列表?
- mysql - 优化 SQL 查询 - 清理数据库中的旧日志
- android - 复选框父子关系android
- angular - 将 Javascript 脚本导入 Angular
- google-sheets - 将 Strava 与 Google 表格集成
- laravel - 从 Laravel 刀片模板调用数据库
- django - 将 Django 的管理员用户连接到模型