gpt4 book ai didi

regex - URL中作为参数传递的特殊字符

转载 作者:行者123 更新时间:2023-12-03 00:50:45 25 4
gpt4 key购买 nike

要求:需要一种方法来处理特殊字符,例如%&。需要调整以下代码,以便按原样处理通过$Control文件传入的特殊字符。

例如:我在$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

最佳答案

您要对URI进行URL编码。首先添加:

Add-Type -AssemblyName 'System.Web'

然后像这样编码URL:
$controlUri = [System.Web.HttpUtility]::UrlEncode($control)
$site = $ie.Navigate("https://www.xxxy.com/search/all?name=$controlUri")

关于regex - URL中作为参数传递的特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27887655/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com