Java parsing XML file exercise-get app icon by app package name-other information (based on Meizu store)

Source: Internet
Author: User
Tags lenovo

1. Parse the package name data file (TXT file) and generate the package an array group:

Package Jsouphtml;import Java.io.bufferedreader;import Java.io.file;import java.io.filereader;import Java.io.ioexception;public class Getpackagename {public static string[] Getpackagename (string filename) {string Packagename[]=null; BufferedReader Istream=null; String line = null; File Packagenames = new file (filename);//"D:\\packagenames.txt" try {stringbuffer content=new stringbuffer (); iStream = New BufferedReader (New FileReader (Packagenames)), while ((Line=istream.readline ())!=null) {Content.append (Line.trim ());} Packagename=content.tostring (). Split (",");} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} Finally{if (Istream!=null) try {istream.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();}} return packagename;}}

2, crawl data, generate icon file (based on the Meizu App Store):

Package Jsouphtml;import Java.io.file;import Java.io.fileoutputstream;import java.io.ioexception;import Java.io.inputstream;import Java.io.outputstream;import Java.net.url;import Java.net.urlconnection;import Org.jsoup.jsoup;import Org.jsoup.nodes.document;import Org.jsoup.nodes.element;import org.jsoup.select.Elements; public class Mztheme {public static void main (string[] args) {InputStream InputStream = Null;outputstream OutputStream = n ull;try {String url = "Http://app.flyme.cn/apps/public/detail?package_name="; String packagenames[] = getpackagename.getpackagename ("D:\\packagenames.txt"); System.out.println (Packagenames.length), for (int i =1;i<packagenames.length;i++) {System.out.println (i);D Ocument doc = jsoup.connect (url +packagenames[i]). get (); if (Doc.getelementsbyclass ("Mz_content mz_container clearfix" ). IsEmpty ()) {Element cElement = Doc.getelementbyid ("theme_content"); Elements IMGs = Celement.getelementsbyclass ("app_img"); String src = Imgs.first (). attr ("src"); System.out.println (SRC); System.out.println (Packagenames[i]); File icon = new file ("d:\\icons\\" + packagenames[i] + ". png");//Icon storage directory, can be modified according to the situation//1. Get URL urls u = new URL (src);//2. Open Connection URLC Onnection conn = U.openconnection ();//3. Get input stream and write out stream inputstream = Conn.getinputstream (); outputstream = new FileOutputStream (icon);//4. Write the source code to memory (set encoding) byte[] b = new Byte[2048];int len = 0;while (len = Inputstream.read (b))! =-1) {Outputstream.write (b, 0, Len);}} Else{system.out.println (packagenames[i]+ ", No_exit");}} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} finally {//close I/otry {if (OutputStream! = N ull) Outputstream.close (); if (InputStream! = null) inputstream.close (); catch (IOException e) {e.printstacktrace ();}}}}

Generate icon file (based on app Po):

Package Jsouphtml;import Java.io.file;import Java.io.fileoutputstream;import java.io.ioexception;import Java.io.inputstream;import Java.io.outputstream;import Java.net.url;import Java.net.urlconnection;import Org.jsoup.jsoup;import Org.jsoup.nodes.document;import Org.jsoup.nodes.element;import org.jsoup.select.Elements;  public class Jsouphtml {public static void main (string[] args) {InputStream InputStream = Null;outputstream OutputStream = null;try {//string url = "http://app.flyme.cn/apps/public/detail?package_name=";//string url = "http://app.mi.com/ details?id= ";//string url =" http://www.wandoujia.com/apps/"; String url = "Http://sj.qq.com/myapp/detail.htm?apkName="; String packagenames[] = getpackagename.getpackagename ("D:\\packagenames.txt"); System.out.println (Packagenames.length), for (int i =1;i<packagenames.length;i++) {System.out.println (i);D Ocument doc = jsoup.connect (url +packagenames[i]). get (); Element content = Doc.getelementbyid ("Det-icon");//elements IMGs = doc.getelementsByclass ("app_img"); Meizu App Store//elements IMGs = Doc.getelementsbyclass ("Yellow-flower"); if (Content.isblock ()) {Elements IMGs = Doc.getelementsbytag ("img"); String src = Imgs.first (). attr ("src"); SYSTEM.OUT.PRINTLN (SRC); System.out.println (Packagenames[i]); File icon = new file ("d:\\yingyongbao\\" + packagenames[i] + ". png");//1. Get URL urls u = new URL (src);//2. Open Connection URLConnection conn = U.openconnection ();//3. Get the input stream and write out the stream inputstream = Conn.getinputstream (); outputstream = new FileOutputStream (icon)  ;//4. Write the source code to memory (set encoding) byte[] b = new Byte[2048];int len = 0;while (len = Inputstream.read (b))! =-1) {Outputstream.write (b, 0, Len);}} Else{system.out.println (packagenames[i]+ ", No_exit");}} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} finally {//close I/otry {if (OutputStream! = N ull) Outputstream.close (); if (InputStream! = null) inputstream.close ();  catch (IOException e) {e.printstacktrace ();}}} }

Package name Data (meizu.txt):

Air.fyzb3,air.tv.douyu.android,android.zhibo8,bubei.tingshu,cc.fotoplace.app,chinatelecom.mwallet, Cld.navi.mainframe,cmb.pb,cmccwm.mobilemusic,cn.amazon.mshop.android,cn.andouya,cn.banshenggua.aichang, Cn.buding.martin,cn.cj.pe,cn.cntv,cn.colorv,cn.com.fetion,cn.com.kuting.activity,cn.com.nd.s, Cn.com.opda.android.clearmaster,cn.eclicks.drivingtest,cn.eclicks.wzsearch,cn.ibuka.manga.ui,cn.j.guang, Cn.j.hers,cn.jingling.motu.photowonder,cn.jj,cn.kuwo.player,cn.kuwo.tingshu,cn.ledongli.ldl,cn.mama.activity, Cn.mucang.drunkremind.android,cn.mucang.kaka.android,cn.mucang.xiaomi.android,cn.mucang.xiaomi.android.wz, Cn.opda.a.phonoalbumshoushou,cn.relian99,cn.wps.moffice_eng,com. A17zuoye.mobile.homework,com.achievo.vipshop,com.adobe.flashplayer,com.adobe.reader, Com.akazam.android.wlandialer,com.alensw.picfolder,com.alex.lookwifipassword,com.ali.money.shield, Com.alibaba.android.rimet,com.alibaba.wireless,com.android.bankabc,com.android.cheyooh,com.android.chrome, Com.android.comicsisland.activity,cOm.android.dazhihui,com. Android56,com.androidesk,com.androidesk.livewallpaper,com.anguanjia.safe,com.anguanjia.security, Com.anjuke.android.app,com.antutu.abenchmark,com.anzogame.game,com.anzogame.lol,com.aoratec.wifimanager, Com.autoconnectwifi.app,com.autohome.mycar,com.autonavi.cmccmap,com.autonavi.minimap, Com.autonavi.xmgd.navigator,com.babytree.apps.pregnancy,com.baidu.baidumap,com.baidu.baidutranslate, Com.baidu.browser.apps,com.baidu.easyroot,com.baidu.hao123,com.baidu.homework,com.baidu.iknow,com.baidu.input, Com.baidu.lbs.waimai,com.baidu.netdisk,com.baidu.news,com.baidu.searchbox,com.baidu.tieba,com.baidu.video, Com.baozoumanhua.android,com.baozun.customer.main,com.beastudio.sflashlight,com.besttone.elocal, com.besttone.hall,com.bilin.huijiao.activity,com.blackbean.cnmeach,com.brianbaek.popstar,com.browser2345, Com.budejie.www,com.calendar.ui,com.centurysoft.fruityrobo,com.changba,com.chaozh.ireaderfree, Com.chinamobile.cmccwifi,com.chinamobile.contacts.im,com.chinamworld.bocmbci,com. chinamworld.main,com.chinatelecom.bestpayclient,com.chinatelecom.pim,com.cinema2345,com.cleanmaster.mguard_cn , Com.cleanmaster.security_cn,com.cmbchina.ccd.pluto.cmbactivity,com.cmcc.cmvideo,com.codoon.gps, Com.coohuaclient,com.cootek.smartdialer,com.corp21cn.flowpay,com.ct.client,com.cubic.autohome, Com.cubic.choosecar,com.culiu.purchase,com.culiu.tenpics,com.culiukeji.huanletao,com.dangdang.buy2, Com.daohang2345,com.dawx.seafloor,com. Dbgame.diablolol,com.dewmobile.kuaiya,com.dianping.v1,com.dianxinos.dxhome,com.dianxinos.superuser, Com.didapinche.booking,com.dou_pai. Doupai,com.douguo.recipe,com.dp.android.elong,com.dsi.ant.plugins.antplus,com.duoduo.child.story, Com.duokan.reader,com.duomi.android,com.duowan.bi,com.duowan.groundhog.mctools,com.duowan.kiwi, Com.duowan.lolbox,com.duowan.mobile,com.dw.btime,com.eastmoney.android.berlin,com.eg.android.alipaygphone, Com.erdo.android.fjdxcartoon,com.esbook.reader,com.estrongs.android.pop,com.evernote,com.fanli.android.apps, Com.fenbi.android.gaozhOng,com.fenbi.android.solar,com.flightmanager.view,com.fone.player,com.frego.flashlight, COM.FUNSHION.VIDEO.MOBILE,COM.GAMELOFT.ANDROID.ANMP.GLOFTA8CN,COM.GAMELOFT.ANDROID.ANMP.GLOFTDMCN, Com.ganji.android,com.gau.go.launcherex,com.geili.koudai,com.gift.android,com.google.android.apps.docs, Com.google.android.apps.maps,com.google.android.inputmethod.pinyin,com.google.android.street,com.gotokeep.keep , Com.gozap.labi.android,com.gtgj.view,com.gwsoft.imusic.controller,com.haishiydmm.fish, Com.handsgo.jiakao.android,com.haobao.wardrobe,com.haodou.recipe,com.happyteam.dubbingshow, Com.hexin.plat.android,com.hf,com.hipu.yidian,com.hisunflytone.android,com.hjwordgames,com.hola.launcher, Com.huaqian,com.huati,com.huawei.fans,com.huawei.hidisk,com.huluxia.mctool,com.hunantv.imgo.activity, Com.husor.beibei,com.husor.mizhe,com.ibox.flashlight,com.icbc,com.icbc.im,com.icoolme.android.weather, Com.ifeng.news2,com.ifeng.newvideo,com.iflytek.cmcc,com.iflytek.inputmethod,com.iflytek.ringdiyclient, Com.ifreetalk. ftalk,com.ijinshan.browser_fast,com.ijinshan.duba,com.ijinshan.kbatterydoctor,com.imangi.templerun2, Com.immomo.momo,com.imusic.iting,com.instamag.activity,com.intsig.bizcardreader,com.intsig.camscanner, Com.iooly.android.lockscreen,com.itings.myradio,com.iyd.reader.readingjoy,com.jiasoft.swreader, Com.jingdian.tianxiameishi.android,com.jingdong.app.mall,com.jiongji.andriod.card,com.jiubang.goscreenlock, Com.jiuyan.infashion,com.jm.android.jumei,com.jsmcc,com.juanpi.ui,com.jxedt,com.kandian.vodapp, Com.kiloo.subwaysurf,com.kingreader.framework,com.kingroot.kinguser,com.kingroot.master,com.kingsoft, Com.koudai.weidian.buyer,com.koudai.weishop,com.kuaikan.comic,com.kugou.android,com.kugou.android.ringtone, Com.kunpeng.babyting,com.kxshow,com.lbe.security,com.le123.ysdq,com.lectek.android.sfreader,com.leixun.taofen8 , Com.lejent.zuoyeshenqi.afanti,com.lemon.faceu,com.lenovo.anyshare,com.lenovo.calendar,com.lenovo.safecenter, Com.lesports.glivesports,com.letv.android.client,com.lingan.seeyou,com.liNgdong.client.android,com.liveaa.education,com.longzhu.tga,com.lovebizhi.wallpaper,com.ludashi.benchmark, Com.m4399.gamecenter,com.manboker.headportrait,com.mapbar.android.mapbarmap,com.mci.smagazine, Com.meelive.ingkee,com.meilishuo,com.meitu.makeup,com.meitu.meipaimv,com.meitu.meiyancamera,com.meitu.wheecam, Com.melot.meshow,com.miantan.myoface,com.microsoft.office.onenote,com. Mobileticket,com.mogujie,com.moji.mjweather,com.moxiu.launcher,com.mt.mtxx.mtxx,com.mydream.wifi,com.mymoney, Com.mymoney.sms,com.nd.android.pandahome2,com.nd.android.pandareader,com.netease.cloudmusic,com.netease.mail, Com.netease.newsreader.activity,com.netease.pris,com.nice.main,com.nuomi,com.ophone.reader.ui, Com.oupeng.mini.android,com.p1.mobile.putong,com.panda.videoliveplatform,com.pingan.lifeinsurance, Com.pingan.pabank.activity,com.pingan.papd,com.pingan.pinganwifi,com.pingco.android.mix,com.pingco.jc258cup, Com.pipcamera.activity,com.pplive.androidphone,com.qianshoulian.app,com.qidian.qdreader,com.qigame.lock, Com.qihoo.cleandroid_cn,com.qiyi.video,com.qq.ac.android,com.qq.qcloud,com.qq.reader,com.quanleimu.activity, Com. Qunar,com.quvideo.xiaoying,com.qzone,com.renren.mobile.android,com.rinzz.noonedies,com.rongcai.show, Com.rrh.jdb,com.sankuai.meituan,com.sankuai.meituan.takeoutnew,com.sankuai.movie,com.sdu.didi.gsui, Com.sdu.didi.psnger,com.sec.chaton,com.sec.pcw,com.sg.sledog,com.shoujiduoduo.ringtone, Com.shoujiduoduo.wallpaper,com.shuame.mobile,com.shuqi.controller,com.sina.news,com.sina.weibo, Com.sinovatech.unicom.ui,com.slanissue.apps.mobile.erge,com.smile.gifmaker,com.snda.wifilocating, Com.soft.blued,com.sogou.activity.src,com.sogou.map.android.maps,com.sogou.novel,com.sohu.inputmethod.sogou, Com.sohu.newsclient,com.sohu.sohuvideo,com.soufun.app,com.soulgame.bubble,com.ss.android.article.news, Com.ss.android.essay.joke,com.sskj.flashlight,com.storm.smart,com.sumavision.talktv2,com.suning.mobile.ebuy, com.supercell.clashofclans.wdj,com.syezon.wifi,com.tadu.android,com.taobao.ju.android,com.tAOBAO.QIANNIU,COM.TAOBAO.TAOBAO,COM.TAOBAO.TRIP,COM.TELECOM.VIDEO,COM.TELECOM.VIDEO.IKAN4G, Com.tencent.androidqqmail,com.tencent.clover,com.tencent.gallerymanager,com.tencent.hexkog,com.tencent.karaoke , COM.TENCENT.KIHAN,COM.TENCENT.LIGHTALK,COM.TENCENT.MAP,COM.TENCENT.MM,COM.TENCENT.MOBILEQQ, COM.TENCENT.MOBILEQQI,COM.TENCENT.MTT,COM.TENCENT.NEWS,COM.TENCENT.NOW,COM.TENCENT.PAO,COM.TENCENT.PB, COM.TENCENT.PENG,COM.TENCENT.PORTFOLIO,COM.TENCENT.QLAUNCHER,COM.TENCENT.QLAUNCHER.LITE,COM.TENCENT.QQGAME.XQ, Com.tencent.qqlite,com.tencent.qqlive,com.tencent.qqmusic,com.tencent.qqpim,com.tencent.qqpimsecure, COM.TENCENT.QQPINYIN,COM.TENCENT.QT.QTL,COM.TENCENT.RADIO,COM.TENCENT.READING,COM.TENCENT.TMGP.CARROT3, Com.tencent.tmgp.cf,com.tencent.tmgp.gods,com.tencent.tmgp.rungame,com.tencent.tmgp.sgame, Com.tencent.tmgp.ttcz,com.tencent.token,com.tencent.ttpic,com.tencent.unipay,com.tencent.wblog, Com.tencent.wefire,com.tencent.wifimanager,com.tencent.zebra,com.tenpay.android,com.thestore.main,com.tianqI2345,com.tieyou.train.ark,com.tigerknows,com.ting.mp3.android,com.tiqiaa.icontrol,com.tmall.wireless, Com.tongcheng.android,com.tripadvisor.tripadvisor.daodao,com.tuan800.tao800,com.tudou.android,com.tujia.hotel, Com.tuniu.app.ui,com.ucamera.ucam,com.unionpay.uppay,com.ushaqi.zhuishushenqi,com.uu.uunavi,com.vlocker.locker , Com.vmall.client,com.wacai365,com.wangzhi.mamahelp,com.wantu.activity,com.weihua.superphone, Com.welove520.welove,com.wenba.bangbang,com.whatsapp,com.when.coco,com.wififreekey.wifi,com.wochacha,com.wuba, Com.xg.nine,com.xiachufang,com.xiaobanlong.main,com.xiaoenai.app,com.xiaomi.hm.health,com.xiaomi.shop, Com.ximalaya.ting.android,com.xingjiabi.shengsheng,com.xinmei365.font,com.xiudang.jiukuaiyou.ui, Com.xtuone.android.syllabus,com.xunlei.downloadprovider,com.xunlei.kankan,com.xunmeng.pinduoduo, Com.ygkj.chelaile.standard,com.yhouse.code,com.yibasan.lizhifm,com.yiche.autoeasy,com.yiche.price,com.yipiao, com.yixia.videoeditor,com.yixia.xiaokaxiu,com.yoloho.dayima,com.youan.unIversal,com.youba.barcode,com.youdao.dict,com.youdao.note,com.youku.phone,com.youloft.calendar, Com.yourdream.app.android,com.youyuan.yyhl,com.yuedong.sport,com.yulong.android.coolmall, Com.yulong.android.coolyou,com.yx,com.yy.yymeet,com.zdworks.android.zdclock,com.zhangdan.app,com.zhihu.android , Com.zhiqupk.root,com.zte.heartyservice,com.ztgame.bob,com.zuobao.xiaobao,ctrip.android.view,dopool.player, Flipboard.cn,fm.qingting.qtradio,fm.xiami.main,howbuy.android.piggy,internetradio.all,me.chunyu.chunyudoctor, Me.ele,my.beautycamera,oms.mmc.app.almanac_inland,org.cocos2d.fishingjoy3,org.fungo.fungolive,qsbk.app, Sina.mobile.tianqitong,smskb.com,sogou.mobile.explorer,tv.danmaku.bili,tv.pps.mobile,viva.reader, Vstudio.android.camera360,wb.gc.xmxx.zxb

  

This article just provides a way of thinking, you can according to your own needs to further develop, such as access to download volume, etc...

Java parsing XML file exercise-get app icon by app package name-other information (based on Meizu store)

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.