Paip. obtain data from HTML select

Source: Internet
Author: User

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
}

----------------- ActualCode----------------

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 ";

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.