要求:点击下面$ ie.navigate中指定的网页后。我需要访问下一个打开的Web页面的HTML/OuterHTML源代码。单击后访问下一个网页
例如:当我打开https://www.healthkartplus.com/search/all?name=Sporanox(通过设置$ control = Sporanox),下面的代码只需点击第一个匹配链接。点击链接后,我需要访问生成页面的HTML。
更新:提到另一个SO问题,并得知我们可以搜索适当的窗口。代码似乎适用于某些情况,但不是所有情况。对于$ ie2,我在访问Document属性时遇到问题。
function getStringMatch
{
# Loop through all 2 digit combinations in the $path directory
foreach ($control In $controls)
{
$ie = New-Object -COMObject InternetExplorer.Application
$ie.visible = $true
$site = $ie.Navigate("https://www.healthkartplus.com/search/all?name=$control")
$ie.ReadyState
while ($ie.Busy -and $ie.ReadyState -ne 4){ sleep -Milliseconds 100 }
$link = $null
$link = $ie.Document.get_links() | where-object {$_.innerText -eq "$control"}
$link.click()
while ($ie.Busy -and $ie.ReadyState -ne 4){ sleep -Milliseconds 100 }
$ie2 = (New-Object -COM 'Shell.Application').Windows() | ? {
$_.Name -eq 'Windows Internet Explorer' -and $_.LocationName -match "^$control"
}
# NEED outerHTML of new page. CURRENTLY it is working for some.
$ie.Document.body.outerHTML > d:\med$control.txt
}
}
$controls = "Sporanox"
getStringMatch
在页面首先导航到你有两个斯皮仁诺链接,你想要两个目标的HTML?只有一个? –
只是第一个。 – Powershel