GitHub repository: Corybyte/-pubg-steam-json-
Created: 2021-06-27T19:43:37Z
Description: package main.java.jsoup;   import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.google.gson.JsonArray; import main.java.util.Mysql; import org.apache.commons.codec.digest.Md5Crypt; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; import org.apache.http.HttpStatus; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import sun.security.provider.MD5; import sun.util.resources.cldr.ml.CalendarData_ml_IN;  import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.List;     public  class Jsoup_GetContext  {      public  static  void  main(String[] args) {          demo("76561198382112423","admin");      }       public  static  String  demo (String steam17ID,String username){         //1.生成httpclient，相当于该打开一个浏览器         CloseableHttpClient httpClient = HttpClients.createDefault();         CloseableHttpResponse response = null;         //2.创建get请求，相当于在浏览器地址栏输入 网址/578080/2?l=tchinese&count=5000         HttpGet request = new HttpGet("https://steamcommunity.com/inventory/"+steam17ID+"/578080/2?l=tchinese&count=5000");         request.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36");         request.setHeader("Cookie", "steamMachineAuth76561199164898599=ACFE14459CA5AE25E1818D48FECBDD5A1A429A03; browserid=2325526493376546392; timezoneOffset=28800,0; _ga=GA1.2.1521504173.1622894872; sessionid=fd56e3ae23fd182063aae56d; steamCountry=HK|1438b9177c1f521a96557c73a3b07e5a; _gid=GA1.2.1153586228.1624283355; strInventoryLastContext=578080_2");         request.setHeader("Connection", "keep-alive");         request.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");         request.setHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");         HttpHost proxy = new HttpHost("127.0.0.1", 8889);         RequestConfig config = RequestConfig.custom().setProxy(proxy).build();         request.setConfig(config);          try {             //3.执行get请求，相当于在输入地址栏后敲回车键             response = httpClient.execute(request);             //4.判断响应状态为200，进行处理             if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {                 //5.获取响应内容                 HttpEntity httpEntity = response.getEntity();                 String html = EntityUtils.toString(httpEntity, "utf-8");                   JSONObject jsonObject = JSONObject.parseObject(html);                  getdescriptions(html,username,steam17ID);                  System.out.println("-------------");                   return "200";              } else {                 //如果返回状态不是200，比如404（页面不存在）等，根据情况做处理，这里略                 System.out.println("返回状态不是200");                 System.out.println(EntityUtils.toString(response.getEntity(), "utf-8"));                 return "500";             }         } catch (ClientProtocolException e) {             e.printStackTrace();         } catch (IOException e) {             e.printStackTrace();         } finally {             //6.关闭             HttpClientUtils.closeQuietly(response);             HttpClientUtils.closeQuietly(httpClient);         }         return "404";     }         public static String getdescriptions(String html,String user_name,String steam17ID) throws IOException {             JSONObject jsonObject = JSONObject.parseObject(html);             JSONArray descriptions = jsonObject.getJSONArray("descriptions");             downlnadIcon_url(descriptions,user_name,steam17ID);// icon_url downlnad                for (int i = 0; i < descriptions.size(); i++) {                 // System.out.println("classid: " + descriptions.getJSONObject(i).getString("classid") + "\n"                    //     + "icon_url:" + descriptions.getJSONObject(i).getString("icon_url") + "\n"                     //    + "market_hash_name:" + descriptions.getJSONObject(i).getString("market_hash_name") + "\n"                       //  + "marketable:" + descriptions.getJSONObject(i).getString("marketable") + "\n" +                        // "-----------------------------------------------------------------");                   String classid=descriptions.getJSONObject(i).getString("classid");                  String market_hash_name=descriptions.getJSONObject(i).getString("market_hash_name");                  String marketable=descriptions.getJSONObject(i).getString("marketable");                    getclassid(classid);               }              return null;         }        public  static  String downlnadIcon_url(JSONArray descriptions,String user_name,String steam17ID) throws IOException {         for (int i = 0; i < descriptions.size(); i++) {             URL url1 = new URL("https://community.cloudflare.steamstatic.com/economy/image/" + descriptions.getJSONObject(i).getString("icon_url"));             URLConnection uc = url1.openConnection();             InputStream inputStream = uc.getInputStream();             File file = new File("/home/cg/public/icon_url/" + "admin" + "/" + "public_IMG" + "/" + descriptions.getJSONObject(i).getString("market_hash_name") + ".jpg");             if (file.exists() == true) {                 System.out.println("1");             } else {                 FileOutputStream out =                         new FileOutputStream("/home/cg/public/icon_url/" + "admin" + "/" + "public_IMG" + "/" + descriptions.getJSONObject(i).getString("market_hash_name") + ".jpg");                 int j = 0;                 while ((j = inputStream.read()) != -1) {                     out.write(j);                 }                 inputStream.close();             }         }         return null;     }              public static String getclassid(String classid){                  //System.out.println("classid:"+classid);                  return classid;             }              public  static  String  getmarket_hash_name(String market_hash_name){                  return market_hash_name;             }              public  static  String   marketable(String  marketable){                  return  marketable;             }     }