码迷,mamicode.com
首页 > 移动开发 > 详细

Android 利用jsoup 抓取腾讯应用市场的软件APP,作为我们自己应用的数据

时间:2014-11-29 10:27:47      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:des   android   style   http   io   ar   os   sp   java   

最近想做自己的一个应用市场,但是苦于,没有应用数据,因此,用jsoup来抓取,腾讯应用市场的软件APP各种数据,

挺不错的。哈哈。你要啥数据都有哈。 不错。

直接看代码


package com.example.jsoup;


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;


import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;


public class MainActivity extends Activity {
private TextView apps;
List<AppDownloadInfo> liAppDownloadInfos = new ArrayList<AppDownloadInfo>();
private String app = "http://android.myapp.com/myapp/category.htm?orgame=1"; 
private String appdetail = "http://android.myapp.com/myapp/detail.htm?apkName=com.tencent.mobileqq";
private String urlhead = "http://android.myapp.com/myapp/";


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
apps = (TextView) findViewById(R.id.apps);


// ThreadPoolManager.getInstance().addTask(new getNetApp());
ThreadPoolManager.getInstance().addTask(new getNetAppDetail());
}


public class getNetApp implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub


Document doc;
try {
doc = Jsoup.connect(app).get();
Elements ListDiv = doc.getElementsByAttributeValue("class",
"app-info-desc");
for (Element element : ListDiv) {
AppDownloadInfo appDownloadInfo = new AppDownloadInfo();
appDownloadInfo.setAppname(element.select("a").attr(
"appname"));
appDownloadInfo.setAppsize(element.getElementsByClass(
"size").text());
appDownloadInfo.setTypename(element.getElementsByClass(
"download").text());
appDownloadInfo.setHref(urlhead
+ element.select("a").attr("href"));
appDownloadInfo.setIconurl(element.select("a").attr(
"appicon"));
appDownloadInfo.setPackagename(element.select("a").attr(
"apk"));
appDownloadInfo.setDownloadUrl(element.select("a").attr(
"ex_url"));
liAppDownloadInfos.add(appDownloadInfo);
appDownloadInfo = null;
}


MainActivity.this.runOnUiThread(new Runnable() {


@Override
public void run() {
// TODO Auto-generated method stub
apps.setText(liAppDownloadInfos.toString());
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}


}


public class getNetAppDetail implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub


Document doc;
try {
doc = Jsoup.connect(appdetail).get();
List<String> tupian = new ArrayList<String>();
Elements ListDiv = doc.getElementsByAttributeValue("class",
"pic-img-box");
for (Element element : ListDiv) {
tupian.add(element.select("img").attr("data-src"));
}


Elements ListDiv2 = doc.getElementsByAttributeValue("class",
"det-othinfo-data");

final List<String> string=new ArrayList<String>();//获取到    版本号,以及开发商
for(Element element : ListDiv2){
if(element.childNodeSize()>0){
string.add(element.text());
}

}


MainActivity.this.runOnUiThread(new Runnable() {


@Override
public void run() {
// TODO Auto-generated method stub
apps.setText(string.toString());
}
});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}


}


}

Android 利用jsoup 抓取腾讯应用市场的软件APP,作为我们自己应用的数据

标签:des   android   style   http   io   ar   os   sp   java   

原文地址:http://blog.csdn.net/xufeifandj/article/details/41593391

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!