BILL
BILL

Reputation: 4869

Using Html Agility Pack for parsing Html

I have this html

<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<div style="background: #5b7fa6; padding: 2px 3px 3px 3px; border-bottom: 1px solid #6f91bb;">
<b style="color: #FFFFFF;">Gain Access to VK</b>
</div>
<div style="border-top: 1px solid #4a6a91; padding:10px;">
<div style="background: #ffffff; border: 1px solid #adbbca; padding: 5px;'">
<form method="POST" action="https://login.vk.com/?act=login&amp;soft=1&amp;utf8=1">
</form>
</div>  
</div>
</body></html>

I want to get value of action attribute in form element. I using this code

    HtmlNode formNode = htmlDoc.DocumentNode.SelectSingleNode("html/body/div[2]/div/form");
    if (formNode != null)
    {
        var action = formNode.GetAttributeValue("action", string.Empty);
        if(!string.IsNullOrEmpty(action))
        {
            //to do 
        }
    }

But formNode is null. I think that the problem in 'DOCTYPE'. How to solve this problem?

Upvotes: 2

Views: 511

Answers (1)

Prashanth Thurairatnam
Prashanth Thurairatnam

Reputation: 4361

since form tag occurs only once why not try something like this

HtmlNode formNode = htmlDoc.DocumentNode.SelectSingleNode("//form");

Upvotes: 1

Related Questions