Java bulk collection pea pod site Android application icon and package name
- 2020-04-01 03:22:00
- OfStack
Android theme developer's theme, if you want to replace the third-party app icon, you must know the package name of the app. In fact, it is very simple to know the package name of the application. Directly open Google Play or peapod in the browser, and open the page of an application. If you look at the url, you will find that the package name of the application is followed by the "/" character at the end of the url!
It is estimated that someone wants to get down the ICONS and package names of commonly used applications, so wrote a small program in Java, batch grab pea pod "all software" according to the total download ranking of 1 to 20 pages of application ICONS and package names.
All ICONS are named with the packageName, there is a packageName. TXT file, containing the application name corresponding to the packageName, easy to find.
Java source code
Share this Java applet. Note that if the structure of the peapod web page changes (it rarely changes), the applet needs to be modified.
The following code may be invalid, for reference only!
package im.garth.AppIconDownloader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.Map.Entry;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class AppIconDownloader {
public static void main(String[] args) {
String rootUrl = "http://www.wandoujia.com/tag/ All software /total?page=";
//String rootUrl = "http: sqwww.wandoujia.com/tag/ all games /total? Page = ";
//Download the app icon on page 1 to 20
for(int i = 1; i < = 20; i++) {
System.out.println(" 【 download progress 】 : ready to download the first " + i + " page ");
String currentUrl = rootUrl + i;
HashMap<String, String> apps = new HashMap<string , String>();
apps = getAppImageUrl(currentUrl);
//Walk through the HashMap to download the ICONS one by one
for(Entry</string><string , String> entry : apps.entrySet()) {
try{
//Download the icon and store it in the icon directory under the current project directory (please create the icon directory first)
download(entry.getValue(), "icon/" + entry.getKey() + ".png");
}catch(Exception e) {
System.out.println(" Download error: " + entry.getKey());
e.printStackTrace();
}
}
System.out.println(" Download progress: no " + i + " Page download completed ");
}
}
private static HashMap</string><string , String> getAppImageUrl(String url) {
HashMap</string><string , String> apps = new HashMap</string><string , String>();
String appPackageName = "";
String appImageUrl = "";
String appName = "";
String html = getHtmlByUrl(url);
Document doc = Jsoup.parse(html);
Elements elements = doc.select("div.container.clearfix>section.main-col>div.app-blocks>div.app-block>ul.app-list.clearfix>li.app>a.icon-area");
Elements nameElements = doc.select("div.container.clearfix>section.main-col>div.app-blocks>div.app-block>ul.app-list.clearfix>li.app>div.operate>a.name>span.txt");
Elements imageEle;
int i = 0;
for(Element ele : elements) {
//To get the package name
appPackageName = ele.attr("data-pn");
//Get icon url
imageEle = ele.select("img.icon");
appImageUrl = imageEle.get(0).attr("src").replace("68_68", "256_256");
//Join the apps
apps.put(appPackageName, appImageUrl);
//Get the app name
appName = nameElements.get(i).text();
//Output the app name and package name to the file
write2file(" 【 " + appName + " 】 " + appPackageName);
i++;
}
System.out.println(" Download progress: " + url + " The following icon url has been successfully obtained ");
return apps;
}
private static void download(String urlString, String filename) throws Exception {
System.out.println(" Download progress: downloading now " + filename);
//To construct the URL
URL url = new URL(urlString);
//Open the connection
URLConnection con = url.openConnection();
//The input stream
InputStream is = con.getInputStream();
//1K of data buffers
byte[] bs = new byte[1024];
//Length of data read
int len;
//Output file stream
OutputStream os = new FileOutputStream(filename);
//Began to read
while ((len = is.read(bs)) != -1) {
os.write(bs, 0, len);
}
//Over, close all links
os.close();
is.close();
System.out.println(" Download progress: " + filename + " Download successful ");
}
private static String getHtmlByUrl(String url){
String html = null;
//Create the httpClient object
HttpClient httpClient = new DefaultHttpClient();
//The URL is requested by get
HttpGet httpget = new HttpGet(url);
try {
//I get the responce object
HttpResponse responce = httpClient.execute(httpget);
//Return code
int resStatu = responce.getStatusLine().getStatusCode();
//200 normal Nothing else is right & NBSP;
if (resStatu==HttpStatus.SC_OK) {
//Receive the corresponding entity & NBSP;
HttpEntity entity = responce.getEntity();
if (entity!=null) {
//Get the HTML source code
html = EntityUtils.toString(entity);
}
}
} catch (Exception e) {
System.out.println(" Access to the "+url+" Abnormal occurrence !");
e.printStackTrace();
} finally {
httpClient.getConnectionManager().shutdown();
}
return html;
}
private static void write2file(String content) {
File file = new File("icon/packageName.txt");
BufferedWriter writer = null;
try{
if(!file.exists()) {
file.createNewFile();
}
//The parameter true means that the output is appended to the end of the file content without overwriting the original content
writer = new BufferedWriter(new FileWriter(file, true));
//output
writer.write(content);
//A newline
writer.newLine();
} catch(IOException e){
System.out.println(" The output error ");
e.printStackTrace();
} finally {
if( writer != null) {
try {
writer.close();
} catch(IOException e) {
e.printStackTrace();
}
}
}
}
}