2013-04-04 81 views
0

嗨任何人都知道任何好的C#庫,可以選擇包含字符串HTML選擇一個表單標籤,所有輸入項目

<html> 
<body> 
some text or layout 
.. 
<form id="blabla" name="blabla" method="post" action="register.aspx"> 
<input type="hidden" name="token" value="12345"> 
<input type="text" name="username" value=""> 
<input type="text" name="password" value=""> 
</form> 
.. 
some text or layout 
</body> 

string HTML = (above) 
FormObject formtag = GetForm(HTML); // get only the <form>..</form> 
var a = formtag.Method // get or post 
var b = formtag.Action // get the URL it post 

// construct the post string 
// username={0}&password={1}&token=12345 
var poststring = string.Format(GetPostString(formtag), "Anima", "abcdef"); 
// result 
// username=Anima&password=abcdef&token=12345 

內部的形式是否有任何C#庫,可以讓內部的形式,所有的輸入項目表格?

+0

[類似](http://stackoverflow.com/questions/56107/what-is-the-best-方式對語法分析HTML-在-C) – 2013-04-04 06:35:52

回答

1

你可以看看的HTML Agility Pack庫,讓您解析HTML:

var htmlDoc = new HtmlAgilityPack.HtmlDocument(); 
htmlDoc.LoadHtml(html); 
var form = htmlDoc.DocumentNode.SelectSingleNode("//form[@id='blabla']"); 
if (form != null) 
{ 
    ... 
} 
相關問題