如何在Htmldocument中使用urldecode

时间:2016-03-18 04:24:37

标签: vb.net urldecode htmldocumentclass

我有这个网址的{HtmlDocument www.vipme.com/clothing_c900027 因为他们的网站包含编码字符site include special like :/&#47 这是我的代码

    Dim myHtmlDom As HtmlDocument = GetHtmlDocument(requestUrl, item.cookie, "refer", item.pageEncoding)
    Dim myProdDom As HtmlNodeCollection = myHtmlDom.DocumentNode.SelectNodes(item.prodPath)
    For Each inode As HtmlNode In myProdDom
        Dim newProd As New Product()    
        If (String.IsNullOrEmpty(item.urlPath)) Then
             newProd.Url = inode.GetAttributeValue(item.urlAttri, "").Trim()
        Else
            newProd.Url = inode.SelectSingleNode(item.urlPath).GetAttributeValue(item.urlAttri, "").Trim
            newProd.Url = Web.HttpUtility.UrlDecode(inode.SelectSingleNode(item.urlPath).GetAttributeValue(item.urlAttri, "").Trim)
        End If

我调试时似乎无法正常工作 enter image description here

1 个答案:

答案 0 :(得分:0)

我最终将UrlDecode更改为htmldecode方法:

    decodeStr = inode.SelectSingleNode(item.urlPath).GetAttributeValue(item.urlAttri, "")
    newProd.Url = Web.HttpUtility.HtmlDecode(decodeStr).Trim()

并且效果很好