要求:需要處理特殊字符,如%
和&
。需要調整下面的代碼,以便通過$Control
文件來的特殊字符按原樣處理。在URL中傳遞的特殊字符作爲參數
例如:我有$control
文件中的一個條目爲25% Dextrose(25ml)
。我需要一種方式,以便$ie.Navigate
應該簡單導航到https://www.xxxy.com/search/all?name=25% Dextrose(25ml)
。目前它被路由到https://www.xxxy.com/search/all?name=25%% Dextrose(25ml)
(注意在URL中額外%),因此不會找到該網頁。
**Few examples of special characters that need to be tackled:**
'/' - 32care Mouth/Throat
'%' - 3d1% Gel(30g)
'&' - Accustix Glucose & Protein
'/' - Ace Revelol(25/(2.5mg)
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.xxxy.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
有特殊字符的URL處理的一個事實上的標準的方式,這就是所謂的「[URL編碼] (https://en.wikipedia.org/wiki/Percent-encoding)」。 – Biffen
你可以舉一個帶'&'符號的產品的例子嗎? –
已經添加上面的問題的例子。 – Powershel