Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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
C# GetAttribute函数在搜索“时不返回任何值”;“类”;属性,则它始终为空_C#_Html Agility Pack_Getattribute_Htmlelements_Windev - Fatal编程技术网

C# GetAttribute函数在搜索“时不返回任何值”;“类”;属性,则它始终为空

C# GetAttribute函数在搜索“时不返回任何值”;“类”;属性,则它始终为空,c#,html-agility-pack,getattribute,htmlelements,windev,C#,Html Agility Pack,Getattribute,Htmlelements,Windev,我目前正在开发一个C#library,它使用HTTP请求和webBrowser控件。我的库用于WinDev程序,并在WinDev应用程序和web平台(agenda.ch)之间创建直接链接。我需要使用一些WebScraping,所以首先开始使用HtmlAgilityPack,效果很好,但是在WinDev上运行我的库时,当HtmlAgilityPack HtmlDocument被实例化时,库突然停止。。。然后我决定删除HtmlAgilityPack并直接使用System.Windows.FormsH

我目前正在开发一个C#library,它使用HTTP请求和webBrowser控件。我的库用于WinDev程序,并在WinDev应用程序和web平台(agenda.ch)之间创建直接链接。我需要使用一些WebScraping,所以首先开始使用HtmlAgilityPack,效果很好,但是在WinDev上运行我的库时,当HtmlAgilityPack HtmlDocument被实例化时,库突然停止。。。然后我决定删除HtmlAgilityPack并直接使用System.Windows.FormsHtmlElement类来检索所需的信息

这就是我的问题所在: 当使用foreach循环检查文档中的每个HtmlElement时,我只能使用GetAttribute()函数来检查它的类值。但是由于某些原因,返回的值总是空的。我做了很多不同的测试,没有一个给出逻辑响应,这就是为什么我转向StackOverflow。我尝试使用另一个属性名,比如id,效果很好。我只是不明白为什么类属性值不能恢复

private void RecoverClients(HtmlDocument source)
    {
        HtmlDocument doc = source;

        HtmlElementCollection clientSection = doc.GetElementsByTagName("DIV");
        HtmlElement clients;

        foreach (HtmlElement element in clientSection)
        {
            // Tests  
            var test = element.GetAttribute("class"); // Always empty
            var test2 = element.GetAttribute("id"); // When has id attribute, works

            if (element.GetAttribute("class") == "customer_list") // The code I use
            {
                clients = element;
                break;
            }
        }
这是由WebBrowser恢复并发送到RecoverClient函数的HTML代码的一部分


  • < A href=“#客户/xxxx”数据操作=“显示”> ClientNameClientSirName
    client1@tech.ch
  • < A href=“#客户/xxxx”数据操作=“显示”> ClientNameClientSirName
    client2@tech.ch

我不太熟悉
System.Windows.Forms HtmlElement
,但我认为应该是
element.GetAttribute(“className”)我认为这不太符合逻辑,因为它在使用属性名(如“id”或“name”)时有效。我仍在尝试,但没有结果。我还没有找到解决这个问题的方法,我真的不知道它的起源,但我确实找到了另一种解决方法,因为有一个id为的父元素,允许我使用GetElementById()函数,然后遍历节点。