Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.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/asp.net/36.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# 如何从HTML中获取元素_C#_Asp.net_Dom - Fatal编程技术网

C# 如何从HTML中获取元素

C# 如何从HTML中获取元素,c#,asp.net,dom,C#,Asp.net,Dom,您好,我正在尝试将html中的ddl插入System.Collections.ArrayList 我正在生成HttpWebRequest和HttpWebResponse HttpWebResponse RedirectResponse = RedirectToUrl("https://servicestest.com/Pages/Trans.aspx"); Stream streamResponse = RedirectResponse.GetResponseStream(); StreamRe

您好,我正在尝试将html中的ddl插入System.Collections.ArrayList

我正在生成HttpWebRequest和HttpWebResponse

HttpWebResponse RedirectResponse = RedirectToUrl("https://servicestest.com/Pages/Trans.aspx");
Stream streamResponse = RedirectResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
MyHtmlPage= streamRead.ReadToEnd();
现在我在MyHtmlPage(streamRead)中有了所有Html页面,其中有DropDownList,其中包含需要存储在System.Collections.ArrayList(或standart数组,如果可能的话)中的所有数据

这是所有html页面的图片,这是我需要存储的ddl id-
ctl00\u占位符main\u AccountsDDL\u ddlAccounts

<div id="ctl00_PlaceHolderMain_AccountsDDL_ddlAccountsWarrper" class="positionRelative "> 
<select name="ctl00$PlaceHolderMain$AccountsDDL$ddlAccounts"  id="ctl00_PlaceHolderMain_AccountsDDL_ddlAccounts" class="margin5 positionAbsolute"> 
        <option selected="selected" value="1" title=" some thhh ">Some info </option> 
        <option value="2" title=" fff"> some info </option> 

        </select> 

        </div> 

一些信息
一些信息

如何将这些数据从MyHtmlPage推送到array?(服务器端)

您可以用来解析html文档。你可能想调查一下。

我找到了另一种方法来获取包含所有数据的retList

    System.Collections.ArrayList retList = new 
    System.Collections.ArrayList();
    mshtml.HTMLDocument doc = new mshtml.HTMLDocument();
    mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)doc;
    doc2.clear();
    doc2.write(MyHtmlPage);
    mshtml.IHTMLDocument3 doc3 = (mshtml.IHTMLDocument3)doc2;
    mshtml.HTMLSelectElement selectToGet = (mshtml.HTMLSelectElement)doc3.getElementById(IDToGet);
                    if (selectToGet != null)
                    {
foreach (mshtml.HTMLOptionElement optToGet in selectToGet.getElementsByTagName("option"))
                        {
if (optToGet.value != null && optToGet.innerText != null)
     {
         retList.Add(optToGet.value + "\t" + optToGet.innerText);
     }
          else if (optToGet.innerText != null)
            {
               retList.Add("value not found" + "\t" + optToGet.innerText);
             }
                   }
      }