htmlagilitypack在html中选择所有输入元素 [英] htmlagilitypack select all input elemet in html

查看:117
本文介绍了htmlagilitypack在html中选择所有输入元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

请使用htmlagilitypack在代码上为我提供帮助,以选择表单上的所有输入元素(包括select,textarea等),提取输入元素的名称和类型

Hello,

Please help me with code using htmlagilitypack to select all input element (including select, textarea etc), on a form, extracting the input element name and type

Dim htmldoc As HtmlDocument = New HtmlDocument()
        htmldoc.LoadHtml(txtHtml.Text)
        Dim root As HtmlNode = htmldoc.DocumentNode
        If root Is Nothing Then
            tsslStatus.Text = "Error parsing html"
        End If
        ' parse the page content
        For Each InputTag As HtmlNode In root.SelectNodes("//input")
            'get title
            Dim attName As String = Nothing
            Dim attType As String = Nothing
            For Each att As HtmlAttribute In InputTag.Attributes
                Select Case att.Name.ToLower
                    Case "name"
                        attName = att.Value
                        'get href or link
                    Case "type"
                        attType = att.Value
                End Select
                If attName Is Nothing OrElse attType Is Nothing Then
                    Continue For
                End If
                Dim sResult As String = String.Format("Type={0},Name={1}", attType, attName).ToLower

                If txtResult.Text.Contains(sResult) = False Then
                    'Debug.Print(sResult)
                    txtResult.Text &= sResult & vbCrLf
                End If

            Next
        Next



感谢



thanks

推荐答案

HtmlDocument doc = new HtmlDocument();
doc.Load("SomePathToAHTMLDocumentHere");
HtmlNode docNode = doc.DocumentNode;
HtmlNodeCollection nodes = docNode.SelectNodes("//input"); //SelectNodes takes a XPath expression
foreach(HtmlNode node in nodes)
{
    String id   = node.GetAttributeValue("id");    // Fetch id of HTML element
    String name = node.GetAttributeValue("name");  // Fetch parameter name (GET/POST)
    String type = node.GetAttributeValue("type");  // Fetch type of input element
    // Do your processing now
}



转到下载站点并获取CHM文件.这样对您有帮助.

干杯!

--MRB



Go to the download site and fetch the CHM file. That will help you.

Cheers!

--MRB


这篇关于htmlagilitypack在html中选择所有输入元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆