Capture group buying information of Meituan network dom4j

Source: Internet
Author: User

Get the Open API of Meituan from the Internet: (Part intercepted)

<? XML version = "1.0" encoding = "UTF-8"?> <Response code = "0" date = "2011-11-08t17: 09: 33 + 08: 00 "message =" OK "> <deals> <DATA> <deal> <website> Meituan Network </website> <city_name> Beijing </city_name> <city_url> http://bj.meituan.com </ city_url> <deal_id> 179850 </deal_id> <deal_title> for 89 RMB only! Hanashan Korean double package worth RMB 172, other gifts </deal_title> <deal_rank> 0 </deal_rank> <deal_url> http://bj.meituan.com/deal/179850.html </deal_url> <deal_img> http://p0.meituan.net/275.168/deal/201110/21/_1021175915.jpg </strong> <deal_cate> catering </deal_cate> <strong> Korean food </deal_subcate> <deal_desc> for 89 RMB only! Hanashan Korean barbecue double package worth 172 yuan (Roast Pork + roast beef + hanashan stone pot bibimbap + super beef half + roast bacon half + corn salad + juice 2 + fire + wet towel 2 copies ), in addition, you will be given a Fruit tray + 4 dishes before meals + 2 portions of pumpkin porridge. barley tea is offered with unlimited drinks. Blow up the classic Korean food style and burn up the flames of your desire for food ~ </Deal_desc> <value> 172 </value> <price> 89 </price> <rebate> 5.2 </rebate> <sales_min> 10 </sales_min> <sales_num> 1435 </sales_num> <sold_out> NO </sold_out> <is_post> NO </is_post> <start_time> 1320595200 </start_time> <end_time> 1321027199 </end_time> <coupon_start_time> 1320595200 </coupon_start_time> <coupon_end_time> 1325951999 </coupon_end_time> <deal_tips> <! [CDATA [effective period: To; Business Hours: 10: 00-; please make an appointment at each branch by phone at least one day in advance; 4: Optional; please go to the selected store for consumption; only for dine-in, the pre-meal take-out service is not provided. You cannot enjoy other discounts in the store at the same time.]> </deal_tips> <deal_wow> <! [CDATA [<li> national chain stores, Quality Assurance </LI> <li> Korean cuisine, fragrant and attractive </LI> <li> fresh ingredients, special barbecue </LI> <li> clean and tidy, considerate service </LI>]> </deal_wow> </deal> <shops> <shop> <shop_name> Yongfeng road store </shop_name> <shop_dpid> 0 </shop_dpid> <shop_tel> 010-62441099/62441599 </shop_tel> <shop_addr> No. 10, A, east side of liulitun, Yongfeng Road, Northwest Wangzhen, Haidian District (near Zhaozhuang Village) </shop_addr> <shop_area> North taipingzhuang </shop_area> <shop_long/> <shop_lat/> <shop_trafficinfo> Bus: Take route 438/384/365/963 to Zhaozhuang Village station, get off at </shop_trafficinfo> </shop> <shop_name> Wangjing No. 2 store (BoTai store) </shop_name> <shop_dpid> 0 </shop_dpid> <shop_tel> 010-64740566 </shop_tel> <shop_addr> Layer 2, BoTai International Plaza, guangshun North Street, Wangjing, Chaoyang District </shop_addr> <shop_area> Wangjing </shop_area> <shop_long/> <shop_lat/> <shop_trafficinfo> Public Transport: take the 416/446/630/660/682/707/851/913/939/944/966/975/110/Express 113/express bus to get off at the west exit of lizerzhong Street. That is, take the subway line 15 and get off at Wangjing station, exit C, about 800 walk to </shop_trafficinfo> </shop> <shop_name> Shi foying store </shop_name> <shop_dpid> 4499440 </shop_dpid> <shop_tel> 010-85825556/85825557 </shop_tel> <shop_addr> No. 302, building 201, balizhuang north, Chaoyang District </shop_addr> <shop_area> shilibao </shop_area> <shop_long/> <shop_lat/> <shop_trafficinfo>: take the bus No. 440/595, No. 640/675, and No. 991 to get off at the Farmer's Daily News North Station and walk for about 10 meters. That is, </shop_trafficinfo> </shop> <shop_name> six-way store </shop_name> <shop_dpid> 4286479 </shop_dpid> <shop_tel> 010-82306899 </shop_tel> <shop_addr> 2/F, hongong building, No. 7 xueda Road, Haidian District (diagonally opposite to Golden block) </shop_addr> <shop_area> bus stop </shop_area> <shop_long/> <shop_lat/> <shop_trafficinfo>: take the bus 355/438/628/913/Express 110 and get off at the 6th exit station. About 130 walk </shop_trafficinfo> </shop> </shops> </data> </deals> </response>

Captured using the dom4j toolkit. Put the desired information in the class deal. java.

Deal. Java:

Package tuangou; import Java. util. arraylist; import Java. util. iterator; public class deal {private string cityname; private string dealtitle; private string dealurl; private string dealimg; private string dealdesc; private double value; private double price; private int salesmin; // The minimum number of participants is the private int salesnum; // The number of participants is the private int starttime; private int endtime; private arraylist <shop> shops; Public deal () {} Public String getcityname () {return cityname;} public void setcityname (string cityname) {This. cityname = cityname;} Public String getdealtitle () {return dealtitle;} public void setdealtitle (string dealtitle) {This. dealtitle = dealtitle;} Public String getdealurl () {return dealurl;} public void setdealurl (string dealurl) {This. dealurl = dealurl;} Public String getdealimg () {return dealimg;} public void setdealimg (string dealimg) {This. dealimg = dealimg;} Public String getdealdesc () {return dealdesc;} public void setdealdesc (string dealdesc) {This. dealdesc = dealdesc;} public double getvalue () {return value;} public void setvalue (double D) {This. value = D;} public double getprice () {return price;} public void setprice (double D) {This. price = D;} public int getsalesmin () {return salesmin;} public void setsalesmin (INT salesmin) {This. salesmin = salesmin;} public int getsalesnum () {return salesnum;} public void setsalesnum (INT salesnum) {This. salesnum = salesnum;} public int getstarttime () {return starttime;} public void setstarttime (INT starttime) {This. starttime = starttime;} public int getendtime () {return endtime;} public void setendtime (INT endtime) {This. endtime = endtime;} public arraylist <shop> getshops () {return shops;} public void setshops (arraylist <shop> shops) {This. shops = shops;} Public String tostring () {string STR = "cityname: \ t" + cityname + "\ n" + "dealtitle: \ t "+ dealtitle +" \ n "+" dealurl: \ t "+ dealurl +" \ n "+" dealimg: \ t "+ dealimg +" \ n "+" dealdesc: \ t "+ dealdesc +" \ n "+" value: \ t "+ value +" \ n "+" Price: \ t "+ Price +" \ n "+" salesmin: \ t "+ salesmin +" \ n "+" salesnum: \ t "+ salesnum +" \ n "+" starttime: \ t "+ starttime +" \ n "+" endtime: \ t "+ endtime +" \ n "; for (iterator <shop> I = shops. iterator (); I. hasnext ();) {shop = I. next (); STR = STR + shop. tostring () ;}return STR ;}}

Because a group purchase information may correspond to multiple consumption locations, you have to write a class shop. Java:

package tuangou;public class Shop {private String shopName;private String shopAddr;private String longitude;private String latitude;public Shop() {}public String getShopName() {return shopName;}public void setShopName(String shopName) {this.shopName = shopName;}public String getShopAddr() {return shopAddr;}public void setShopAddr(String shopAddr) {this.shopAddr = shopAddr;}public String getLongitude() {return longitude;}public void setLongitude(String longitude) {this.longitude = longitude;}public String getLatitude() {return latitude;}public void setLatitude(String latitude) {this.latitude = latitude;}public String toString() {String str = "shopName:\t\t" + shopName + "\n" + "shopAddr:\t\t"+ shopAddr + "\n" + "shopLongitude:\t\t" + longitude + "\n"+ "shoplatidude:\t\t" + latitude + "\n";return str;}}

In this case, the XML parsing class will be written below.

Package COM. meituan; import Java. io. file; import Java. io. fileinputstream; import Java. io. filenotfoundexception; import Java. io. inputstream; import Java. util. arraylist; import Java. util. iterator; import Java. util. list; import Org. dom4j. document; import Org. dom4j. extends entexception; import Org. dom4j. element; import Org. dom4j. io. saxreader; import tuangou. deal; import tuangou. shop; public class meituanxmlparse {publi C void parsexml (string filename) {document = parse2docment (filename); List datalist = document. selectnodes ("/response/deals/Data"); For (iterator <element> I _data = datalist. iterator (); I _data.hasnext ();) {// the following processes/response/deals/data/deal and processes each group buying information element dataele = (element) I _data.next (); deal meituanone = New Deal (); arraylist shops = new arraylist (); shop = new shop (); element dealele = (Element) dataele. element ("deal"); meituanone. setcityname (dealele. element ("city_name "). gettexttrim (); meituanone. setdealtitle (dealele. element ("deal_title "). gettexttrim (); meituanone. setdealurl (dealele. element ("deal_url "). gettexttrim (); meituanone. setdealimg (dealele. element ("deal_img "). gettexttrim (); meituanone. setdealdesc (dealele. element ("deal_desc "). gettexttrim (); If (dealele. element ("value "). gettex Ttrim (). Matches ("\ D + \\.? \ D * ") {meituanone. setvalue (double. parsedouble (dealele. element ("value "). gettexttrim ();} else {meituanone. setvalue (0);} meituanone. setprice (double. parsedouble (dealele. element ("price "). gettexttrim (); meituanone. setsalesmin (integer. parseint (dealele. element ("sales_min "). gettexttrim (); meituanone. setsalesnum (integer. parseint (dealele. element ("sales_num "). gettexttrim (); meituanone. setstarttime (integer. parseint (dealele. element ("start_time "). gettexttrim (); meituanone. setendtime (integer. parseint (dealele. element ("end_time "). gettexttrim (); // process the shops element shopsele = (element) dataele. element ("shops"); For (iterator I _shop = shopsele. elementiterator (); I _shop.hasnext ();) {element shopele = (element) I _shop.next (); // system. out. println (shopele. getname (); // = shopelement shopnameele = shopele. element ("shop_name"); string shopname = shopnameele. gettexttrim (); shop. setshopname (shopname); element shopaddrele = (element) shopele. element ("shop_addr"); string shopaddr = shopaddrele. gettexttrim (); shop. setshopaddr (shopaddr); shops. add (Shop); meituanone. setshops (Shops);} system. out. println (meituanone);} // For}/* Get A Document Object */public static document parse2docment (string filename) {saxreader reader = new saxreader () from the XML file (); document document = NULL; file F = NULL; try {f = new file (filename); inputstream in = new fileinputstream (f); document = reader. read (in);} catch (incluentexception e) {// todo auto-generated catch blocke. printstacktrace ();} catch (filenotfoundexception e) {// todo auto-generated catch blocke. printstacktrace ();} return document ;}}

All right, you're done. Write a main test:

package com.meituan;public class testXML {public static void main(String args[]) {MeiTuanXmlParse mtp = new MeiTuanXmlParse();//mtp.parseXml("I:/projects/Andriod/myDo/APIXML/xml/meituanduan.xml");mtp.parseXml("C:/Users/mojia/Desktop/dom4j/task/meituandeals.xml");//System.out.println(mtr.toString());/*String name = "234523452.254"; if(name.matches("\\d+\\.?\\d*")){System.out.println("ok");}else System.out.println("no");*/}}

Look at the results:

Cityname: National dealtitle: dream come true: Nokia's latest Lumia 800 smart machines 10 free to send dealurl: 800 super full Touch Smart machines 10 free to send! Nokia Microsoft partnered with its first flagship, the king of a heli cluster of smart phones, with the latest Windows Phone 7.5 mango operating system. Invite a new user to join or bind one more Sina Weibo lottery number. The probability of winning the prize doubles! Value: 0.0 price: 0.0 salesmin: 1 salesnum: 404344 starttime: 1320336000 endtime: 1320940799 shopname: Meituan shopaddr: Meituan is China's first, largest, and most popular group buying website. Currently, Meituan provides services in major cities in China, you can enjoy high-quality food, entertainment and leisure, wedding photography, beauty salons and other local consumption at a price as low. Customer Service Hotline: 400-660-5335shoplongloud: nullshoplatidude: NULL

Related Article

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.