Paip. obtain data from HTML select
Recently .. There is a withdrawal module. You need to SELECT a bank from the SELECT control .. But the obtained ID value. The bank name must be saved in the background ..
The select html is as follows ..
<SELECT id = Land_Bank
Name = Land_Bank require = "true" msg = "select a bank" operator = "GreaterThan" to = "0" rig = "select a bank"
DataType = "Compare"> <OPTION selected value = 0> select a bank </OPTION> <OPTION
Value = 4> Industrial and Commercial Bank of China </OPTION> <OPTION value = 5> Agricultural Bank of China </OPTION> <OPTION
Value = 12> China Construction Bank </OPTION> <OPTION value = 6> Bank of Communications </OPTION> <OPTION
Value = 9> Bank of China </OPTION> <OPTION value = 30> China Postal Savings Bank </OPTION> <OPTION
Value = 16> China Merchants Bank </OPTION> <OPTION value = 33> China Pudong Development Bank </OPTION> <OPTION
Value = 19> China Citic Bank </OPTION> <OPTION value = 17> China Minsheng Bank </OPTION> <OPTION
Value = 15> Industrial Bank </OPTION> <OPTION value = 13> China Everbright Bank </OPTION> <OPTION
Value = 8> bank of Beijing </OPTION> <OPTION value = 21> bank of Guangzhou </OPTION> <OPTION
Value = 31> Shenzhen Development Bank </OPTION> <OPTION value = 20> Guangdong Development Bank </OPTION> <OPTION
Value = 22> bank of Hangzhou </OPTION> <OPTION value = 27> bank of Ningbo </OPTION> <OPTION
Value = 25> Huaxia Bank </OPTION> <OPTION value = 29> Ping An Bank </OPTION> <OPTION
Value = 18> zheshang bank </OPTION> <OPTION value = 11> Bohai Bank </OPTION> </SELECT>
How to obtain the ID value in select html becomes a problem...
First, I want to use XML to obtain it, but the HTML is not very strict and does not meet the XML conditions .. In the end, my idea is to convert HTML into XML and then use XML to get the. NET version.
HTML Parser library using Winista. Text. HtmlParser;
------------ Detailed design (pseudo code )--------------
1. Save HTML to/banks.txt
2. html = read (curdir + "/banks.txt ")
Xml = convert (html)
Nodelist = getlistByTagname (xml, "option ")
Foreach nodelist
{
If (node. value = bankid)
Return node.txt
}
----------------- Actual code ----------------
Private string getbankname (string bankId)
{
String rootdir = System. Web. HttpContext. Current. Request. PhysicalApplicationPath;
String xmldir = rootdir + "/pay/banks.txt ";
String html = m. filex. read (xmldir, "gbk ");
String xmlstr = m. xml. XMLHelper. CovertHtmlToXml (html, "OPTION ");
// XmlDataDocument xmlDoc = new System. Xml. XmlDataDocument ();
// XmlDoc. LoadXml (xmlstr );
String bname = getbankname (xmlstr, bankId );
Return bname;
// Return "nothisbank ";
}
Private string getbankname (string xmlstr, string bank)
{
XmlDataDocument xmlDoc = new System. Xml. XmlDataDocument ();
XmlDoc. LoadXml (xmlstr );
XmlNodeList list = xmlDoc. GetElementsByTagName ("OPTION ");
Foreach (XmlNode node in list)
{
String val = node. Attributes ["VALUE"]. Value;
String text = node. InnerText;
If (bank. Equals (val ))
Return text;
}
Return "nothisbank ";
}
Author: attilax