0

嗨,任何人都知道任何可以在包含 HTML 的字符串中选择表单的好的 C# 库

<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# 库可以获取表单和表单内的所有输入项?

4

1 回答 1

1

您可以查看HTML Agility Pack允许您解析 HTML 的库:

var htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(html);
var form = htmlDoc.DocumentNode.SelectSingleNode("//form[@id='blabla']");
if (form != null)
{
    ...
}
于 2013-04-04T06:34:40.033 回答