Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex VB.net使用正则表达式提取特定URL_Regex_Vb.net - Fatal编程技术网

Regex VB.net使用正则表达式提取特定URL

Regex VB.net使用正则表达式提取特定URL,regex,vb.net,Regex,Vb.net,我有一个工作代码,但这提取了所有的网站链接 strReg = "<a\s+href\s*=\s*""?([^"" >]+)""?>(.+)</a>" Dim reg As New Regex(strReg, RegexOptions.IgnoreCase) 我应该用我的正则表达式代码更改什么?提前谢谢 以下是我更新的工作代码: Dim links As New List(Of String)() Dim htmlDoc As New HtmlAg

我有一个工作代码,但这提取了所有的网站链接

    strReg = "<a\s+href\s*=\s*""?([^"" >]+)""?>(.+)</a>"
    Dim reg As New Regex(strReg, RegexOptions.IgnoreCase)
我应该用我的正则表达式代码更改什么?提前谢谢


以下是我更新的工作代码:

Dim links As New List(Of String)()
Dim htmlDoc As New HtmlAgilityPack.HtmlDocument()
htmlDoc.LoadHtml(WebSource)
For Each link As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//a[@href]")
    Dim att As HtmlAttribute = link.Attributes("href")

    If att.Value.Contains("/test/") Then
        ListBox1.Items.Add(att.Value)
    End If
Next

它现在用/test/显示所有URL,但我想从google搜索结果中提取URL。有可能吗?

以下内容将仅匹配其中包含“/test/”的标记

streg=“”

以下内容将仅匹配其中包含“/test/”的标记

streg=“”

在谷歌搜索结果中,您需要找到包含链接的元素。例如,下面的示例将从文档中选择
cite
节点

For Each link As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//cite")
    If link.InnerText.Contains("/test/") Then
        ListBox1.Items.Add(link.InnerText)
    End If
Next

在google搜索结果中,您需要找到包含链接的元素。例如,下面的示例将从文档中选择
cite
节点

For Each link As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//cite")
    If link.InnerText.Contains("/test/") Then
        ListBox1.Items.Add(link.InnerText)
    End If
Next

不要使用正则表达式来解析HTML。使用适当的解析,比如。我已经使用HtmlAgilityPack的工作代码更新了我的帖子,但我想从谷歌搜索结果中提取链接。我对如何开始感到困惑。不要使用正则表达式来解析HTML。使用适当的解析,比如。我已经使用HtmlAgilityPack的工作代码更新了我的帖子,但我想从谷歌搜索结果中提取链接。我对如何开始感到困惑。但是显示的链接并不完整,比如:它们带有破碎的点。我想显示完整的URL,但显示的链接并不完整,比如:它们带有断点。我想显示完整的URL
For Each link As HtmlNode In htmlDoc.DocumentNode.SelectNodes("//cite")
    If link.InnerText.Contains("/test/") Then
        ListBox1.Items.Add(link.InnerText)
    End If
Next