Android 利用jsoup 抓取腾讯应用市场的软件APP,作为我们自己应用的数据
最近想做自己的一个应用市场,但是苦于,没有应用数据,因此,用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();
}
}
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。