Download bus routes from major cities (available on mobile phones)

Source: Internet
Author: User

In places like Shenzhen, it is usually several hours to take a bus. I don't know how long it will take to get to the station. It's not convenient to see the brand on the roof, so I just want to put it on my cell phone.
It's okay. net has written a small software that can download bus routes from cities such as Shenzhen (Guangzhou, Dongguan, Foshan, Shanghai, Beijing, Wuhan, Nanjing, Hangzhou, Suzhou, Tianjin, Shenyang, Dalian, Chongqing, Chengdu, Xi'an, and Huizhou) to the mobile phone, this makes it easy to find routes. After all, not everyone uses smart phones to access the Internet.

Key code (after using the. NET balancing group, I understood it for several hours ):

Find the DIV source code based on the class.

Public static matchcollection getdivbyclassname (string strclass, string source)
RegEx Reg = new RegEx (@"(? Is) <Div (? :(?! Class =).) * class = (['"]?) "+ Strclass + @" \ 1 [^>] *> (?> <Div [^>] *> (? <Open>) | </div> (? <-Open>) | (? :(?! </? Div \ B ).)*)*(? (Open )(?!)) </Div> ");
Return Reg. Matches (source );



The download code is as follows:

First download the HTML source code of the page, and then find all bus routes on the page
Find the route name, fare, site, and remarks,

Click the Download button to download the code.

String strformat = txturlformat. Text, strhtml, strbusnum, strserviceinfo, strroute, strps, strsavepath, strsn = combobox1.items. Count> 0? DT. Rows [combobox1.selectedindex] ["Sn"]. tostring (): "SZ ";
Int istart = int. parse (txtstart. Text), iend = int. parse (txtend. Text );
Stringbuilder sbresult = new stringbuilder ();
RegEx regbusnum = new RegEx ("(? Is) <a (?> [^>] +)> (? <Busnum> [^ <] *) </a> ", regexoptions. Compiled );
Matchcollection matitems, matdetail;
WebClient webdownloader = new WebClient ();
Thread thread = new thread (New threadstart (delegate ()
For (INT I = istart; I <= iend; I ++)
Btndownload. Text = string. Format ("downloading ({0}/{1})...", I-istart + 1, iend-istart + 1 );
Strhtml = webdownloader. downloadstring (string. Format (strformat, I); // obtain the webpage source file
Catch (exception ee) {showexception (EE); return ;}
Strhtml = regexhelper. getdivbyclassname ("w720 fleft", strhtml) [0]. value; // parent container of all routes, because there is a div whose class is border below
Matitems = regexhelper. getdivbyclassname (strsn = "SZ "? "Border": "bd_ddd", strhtml); // obtain the route, which is different from the other in Shenzhen.
Foreach (match item in matitems)
Strhtml = item. value;
Strbusnum = regbusnum. Match (strhtml). Groups ["busnum"]. value; // number of buses
Matdetail = regexhelper. getdivbyclassname ("pad8lr LH24", strhtml );
Strserviceinfo = regexhelper. removewhitespace (regexhelper. removemarkup (matdetail [0]. value), ""); // operation time and fare
Strroute = regexhelper. removemarkup (matdetail [1]. Value); // route
Strps = regexhelper. removewhitespace (regexhelper. removemarkup (matdetail [3]. value. indexof ("Remarks ")! =-1? Matdetail [3]. Value: String. Empty); // obtain the remarks.

Sbresult. appendformat ("\ n {0} \ n {1} \ n {2} \ n {3}", strbusnum, strserviceinfo, strroute, strps = string. Empty? String. Empty: strps + "\ n ");
Btndownload. Text = string. Format ("download completed! ");

Strsavepath = path. Combine (application. startuppath, String. Format ("bus_route_1_02.16.txt", strsn ));
Streamwriter Sw = new streamwriter (strsavepath, false, encoding. Default );
Sw. writeline (sbresult. tostring ());
Sw. Close ();

Sbresult. insert (0, String. Format ("(the file has been saved in: {0}) \ n", strsavepath ));
Rtbresult. Text = sbresult. tostring ();
Thread. isbackground = true;
Thread. Start ();
Catch (exception ex)
Showexception (Ex );



Download busroutesearch.rar (the data is provided by the Taobao website. Thank you)


Analysis process of Bus Route download

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: 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.