使用 Powershell 在网站中选择列表项

Selecting List item in a website using Powershell

我正在寻找 select 所附图片中给出的列表项 (3M),该列表项来自使用 powershell 的网站。我在下面尝试过但没有运气。请提出建议 HTML code

$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
m = ($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.
m.click() # Click the "3M" button.

下面的代码也可以帮助点击列表中的 3M 选项。

$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')

$link = $ie.Document.links | Where-Object {$_.outerText -eq '3M'} 
$link.click()