From 5e7b0ed4a154ad067cbcf4aa1a1c7cce32f9864c Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 26 四月 2024 18:02:17 +0800 Subject: [PATCH] 唯品会链接解析升级 --- fanli/src/main/java/com/yeshi/fanli/util/DouYinUtil.java | 174 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 87 insertions(+), 87 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/util/DouYinUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/DouYinUtil.java index e1db0fc..2a0d211 100644 --- a/fanli/src/main/java/com/yeshi/fanli/util/DouYinUtil.java +++ b/fanli/src/main/java/com/yeshi/fanli/util/DouYinUtil.java @@ -1,87 +1,87 @@ -package com.yeshi.fanli.util; - -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.methods.GetMethod; -import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; -import org.jsoup.select.Elements; -import org.yeshi.utils.HttpUtil; -import org.yeshi.utils.StringUtil; - -import com.yeshi.fanli.dto.douyin.DouYinGoods; - -import net.sf.json.JSONObject; - -public class DouYinUtil { - - public static String parseDouYinGoods(String url) { - HttpClient httpClient = new HttpClient(); - GetMethod gm = new GetMethod(url); - try { - httpClient.executeMethod(gm); - String finalUrl = gm.getURI().toString(); - if (finalUrl.startsWith("https://s.click.taobao.com")) { - Document doc = Jsoup.parse(gm.getResponseBodyAsString()); - - Elements els = doc.getElementsByTag("meta"); - for (int i = 0; i < els.size(); i++) { - if (els.get(i).toString().contains("URL=")) { -// System.out.println(els.get(i)..toString()); - } - System.out.println(els.get(i).attr("URL")); - } - } - - } catch (Exception e) { - } - return null; - } - - - /** - * 閫氳繃閾炬帴鑾峰彇鍟嗗搧鏍囬锛屽浘鐗囦俊鎭� - * @param url - * @return - */ - public static DouYinGoods getGoodsInfo(String url) { - if (StringUtil.isNullOrEmpty(url)) - return null; - - try { - String id = null; - int indexOf = url.indexOf("?"); - url = url.substring(indexOf + 1, url.length()-1); - String[] temp = url.split("&"); - for (int i =0; i < temp.length; i ++) { - String content = temp[i]; - if (content.startsWith("id")) { - id = content.split("=")[content.split("=").length-1]; - break; - } - } - - if (StringUtil.isNullOrEmpty(id)) - return null; - - // 璇锋眰鍦板潃 - String requestUrl = "https://ec.snssdk.com/product/fxgajaxstaticitem?b_type_new=0&id=%s"; - // 鎵ц璇锋眰 - String result = HttpUtil.get(String.format(requestUrl,id)); - - if (!StringUtil.isNullOrEmpty(result)) { - JSONObject json = JSONObject.fromObject(result); - JSONObject data = json.getJSONObject("data"); - - DouYinGoods goods = new DouYinGoods(); - goods.setId(id); - goods.setName(data.optString("name")); - goods.setImg(data.optString("img")); - return goods; - - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } -} +package com.yeshi.fanli.util; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.GetMethod; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.select.Elements; +import org.yeshi.utils.HttpUtil; +import org.yeshi.utils.StringUtil; + +import com.yeshi.fanli.dto.douyin.DouYinGoods; + +import net.sf.json.JSONObject; + +public class DouYinUtil { + + public static String parseDouYinGoods(String url) { + HttpClient httpClient = new HttpClient(); + GetMethod gm = new GetMethod(url); + try { + httpClient.executeMethod(gm); + String finalUrl = gm.getURI().toString(); + if (finalUrl.startsWith("https://s.click.taobao.com")) { + Document doc = Jsoup.parse(gm.getResponseBodyAsString()); + + Elements els = doc.getElementsByTag("meta"); + for (int i = 0; i < els.size(); i++) { + if (els.get(i).toString().contains("URL=")) { +// System.out.println(els.get(i)..toString()); + } + System.out.println(els.get(i).attr("URL")); + } + } + + } catch (Exception e) { + } + return null; + } + + + /** + * 閫氳繃閾炬帴鑾峰彇鍟嗗搧鏍囬锛屽浘鐗囦俊鎭� + * @param url + * @return + */ + public static DouYinGoods getGoodsInfo(String url) { + if (StringUtil.isNullOrEmpty(url)) + return null; + + try { + String id = null; + int indexOf = url.indexOf("?"); + url = url.substring(indexOf + 1, url.length()-1); + String[] temp = url.split("&"); + for (int i =0; i < temp.length; i ++) { + String content = temp[i]; + if (content.startsWith("id")) { + id = content.split("=")[content.split("=").length-1]; + break; + } + } + + if (StringUtil.isNullOrEmpty(id)) + return null; + + // 璇锋眰鍦板潃 + String requestUrl = "https://ec.snssdk.com/product/fxgajaxstaticitem?b_type_new=0&id=%s"; + // 鎵ц璇锋眰 + String result = HttpUtil.get(String.format(requestUrl,id)); + + if (!StringUtil.isNullOrEmpty(result)) { + JSONObject json = JSONObject.fromObject(result); + JSONObject data = json.getJSONObject("data"); + + DouYinGoods goods = new DouYinGoods(); + goods.setId(id); + goods.setName(data.optString("name")); + goods.setImg(data.optString("img")); + return goods; + + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } +} -- Gitblit v1.8.0