Collect the latest province, city, district, zip code and telephone code (with source code)

Source: Internet
Author: User

Recently developed projects require the use of provincial, municipal, and district data, because the projects to be developed are also e-commerce websites. when referring to the user experience of Vanke, it was found that it even had the latest released Guangming New Area in Shenzhen, and no data was updated on the Pat network. It seems that fanke is still responsible for data updates, so he learned about its data format, then I spent some time writing a small program to extract the latest province, city, district, zip code and telephone code. The zip code and telephone code are recommended to the user after the user selects the data, this prevents the user from taking the time to query, as shown in the following figure:

 

Download program source code

 

 

A total of three addresses return data:

        private string GetCityDataUrl(string province)        {            string url = "http://my.vancl.com/DeliveryAddress/GetCityData?povinceId={0}&r={1}";            return string.Format(url, JScriptUtil.Escape(province), GetRandom());        }        private string GetDistrictDataUrl(string province, string city)        {            string url = "http://my.vancl.com/DeliveryAddress/GetAreaData?cityId={0}&povinceId={1}&r={2}";            return string.Format(url, JScriptUtil.Escape(city), JScriptUtil.Escape(province), GetRandom());        }        private string GetPostCodeUrl(string province, string city, string district)        {            string url = "http://my.vancl.com/DeliveryAddress/GetPostalCode?povince={0}&city={1}&area={2}&r={3}";            return string.Format(url, Utils.UrlEncode(province), Utils.UrlEncode(city), Utils.UrlEncode(district), GetRandom());        }

 

Core functions:

// Extract the private void dogetvancldata () {string [] provinces = util. provinces. split ('|'); For (INT I = 0; I <provinces. length; I ++) {string Thep = provinces [I]. trim (); this. invoke (New methodinvoker () => {This. label1.text = Thep + "... ";})); // Add the province int pid = getnewid (" Province "); this. invoke (New methodinvoker () => {If (pid = 1) This. textbox1.text + = "insert into [db_momomate]. [DBO]. [province] ([ID], [name]) \ r \ nselect "+ PID. tostring () + ", '" + Thep + "' \ r \ n"; else this. textbox1.text + = "Union \ r \ nselect" + PID. tostring () + ", '" + Thep + "' \ r \ n" ;}); // obtain city data string [] citydata = webrequesthelper. httpget (getcitydataurl (Thep), "", encoding. utf8 ). split ('$'); thread. sleep (10); foreach (string city in citydata) {string theC = city. split (',') [1]. trim (); // city id int cid = getnewid ("city"); string areacode = NULL; // obtain zone data string [] districtdata = webrequesthelper. httpget (getdistrictdataurl (Thep, theC), "", encoding. utf8 ). split ('$'); thread. sleep (10); foreach (string district in districtdata) {string thed = district. split (',') [1]. trim (); // zone ID int did = getnewid ("District"); string [] postdata = webrequesthelper. httpget (getpostcodeurl (Thep, theC, thed), "", encoding. utf8 ). split ('$'); If (areacode = NULL) {areacode = postdata [4];} string postcode = postdata [3]; thread. sleep (10); // Add the partition this. invoke (New methodinvoker () => {If (did = 1) This. textbox3.text + = "insert into [db_momomate]. [DBO]. [District] ([ID], [cityid], [name], [postcode]) \ r \ nselect "+ did. tostring () + "," + CID. tostring () + ", '" + thed + "', '" + postcode + "' \ r \ n"; else this. textbox3.text + = "Union \ r \ nselect" + did. tostring () + "," + CID. tostring () + ", '" + thed + "', '" + postcode + "' \ r \ n" ;})) ;}// Add the city this. invoke (New methodinvoker () => {If (cid = 1) This. textbox2.text + = "insert into [db_momomate]. [DBO]. [City] ([ID], [provinceid], [name], [areacode]) \ r \ nselect "+ CID. tostring () + "," + PID. tostring () + ", '" + theC + "', '" + areacode + "' \ r \ n"; else this. textbox2.text + = "Union \ r \ nselect" + CID. tostring () + "," + PID. tostring () + ", '" + theC + "', '" + areacode + "' \ r \ n" ;});} This. invoke (New methodinvoker () => {if (I = provinces. length-1) {This. label1.text = "done"; this. button1.enabled = true ;}}));}}

 

The final running effect is as follows:

 

In our project, we still need university data. That is the old data for developing the university SNS website in. We put all the data into the database:

 

 

Users who need to extract province, city, and district data can download the program source code: Click to 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: 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.