任何人都知道任何可以在包含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#库可以获取表单和表单中的所有输入项?
答案 0 :(得分:1)
您可以查看允许您解析HTML的HTML Agility Pack
库:
var htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(html);
var form = htmlDoc.DocumentNode.SelectSingleNode("//form[@id='blabla']");
if (form != null)
{
...
}