powershell - 使用 Powershell 在网站中选择列表项
问题描述
我正在寻找使用 powershell 从网站中选择附件图像中给出的列表项 (3M)。我在下面尝试过,但没有运气。请建议 HTML 代码
$ie = New-Object -ComObject InternetExplorer.Application
$ie.visible=$true
$ie.navigate2('https://www.nseindia.com/companies-listing/corporate-filings-insider-trading')
while($ie.Busy) {Start-Sleep 1}
$dropdown = $ie.Document.getElementsByClassName('dayslisting')
($dropdown | where {$_.innerHTML -like "3M"}).Selected = $true
解决方案
我认为您非常接近您的解决方案。这段代码对我有用。我在内联注释以解释我所做的几个更改。
$ie = New-Object -ComObject InternetExplorer.Application
$ie.visible=$true
$ie.navigate2('https://www.nseindia.com/companies-listing/corporate-filings-insider-trading')
while($ie.Busy) {Start-Sleep 1}
$dropdown = $ie.Document.body.getElementsByClassName('dayslisting') # You needed to select .body here to use getElementsByClassName
$3m = ($dropdown[0].all | where {$_.innerHTML -like "3M"}) # Dropdown is a list because classes can be assigned to more than one element. I'm getting all elements of the first list, but you could do something better if you wanted.
$3m.click() # Click the "3M" button.
推荐阅读
- oauth-2.0 - 单页应用程序-Oauth-2:我们需要刷新令牌吗?
- rx-java2 - RxJava2:调用 Flowable.toList 时处理空值
- java - 折线不会出现
- git - 在 netlify 上禁用持续部署
- google-apps-script - 如何获取 admin.directory.userlist api 的访问令牌?
- django - 部署中的 Django 管理页面
- node.js - 无法读取“ID 参数”的属性
- c - 为什么检查字符串文字时 mprobe 会失败?
- c# - Xamarin Forms 中的数据绑定问题
- api - 您可以从 twitter API 获取主题标签搜索结果以嵌入网页吗?