我有以下html模式。
href="{{url}}" class="item-name prdctNm">{{name}}</a><div>
href="/drugs/sporanox-100-mg-33294" class="item-name prdctNm">Sporanox (100 Mg)</a>
href="/drugs/sporan-200-mg-34240" class="item-name prdctNm">Sporan (200 Mg)</a>
href="/drugs/spornid-500-mg-25051" class="item-name prdctNm">Spornid (500 Mg)</a>
我想要得到的产品名称像
Sporanox (100mg), Sporan (200 mg) and Spornid (50mg).
**
更新的解决方案
**:几乎匹配整个页面。从页面开始first instance of
"item-name prdctNm"
到last <\a>
页面-两者之间都匹配。但是,我需要text between "item-name prdctNm" and tag <\a>
在它旁边匹配。
现在,它可以完美运行:
$regex = [RegEx]'"item-name prdctNm"(.[^{}<>]*)</a>'
$url = ‘https://www.xxx.com/search/all?name=sporanox’
$wc = New-Object System.Net.WebClient
$content = $wc.DownloadString($url)
$regex.Matches($content) | ForEach-Object { $_.Groups[1].Value }
使用下面的正则表达式,然后在最后一个打印组索引1,其中Groups[0]
包含整个匹配项并Groups[1]
包含第一个组捕获的字符。
$regex = [RegEx]'"item-name prdctNm">([^}{<>]*)</a>'
$url = ‘https://www.xxx.com/search/all?name=sporanox’
$wc = New-Object System.Net.WebClient
$content = $wc.DownloadString($url)
$regex.Matches($content) | ForEach-Object { $_.Groups[1].Value }
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句