| | |
| | | package com.yeshi.fanli.util.pinduoduo;
|
| | |
|
| | | import java.io.BufferedReader;
|
| | | import java.io.IOException;
|
| | | import java.io.InputStream;
|
| | | import java.io.InputStreamReader;
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.math.BigDecimal;
|
| | | import java.net.URLEncoder;
|
| | |
| | | import javax.script.Invocable;
|
| | | import javax.script.ScriptEngine;
|
| | | import javax.script.ScriptEngineManager;
|
| | | import javax.script.ScriptException;
|
| | |
|
| | | import org.apache.commons.httpclient.HttpClient;
|
| | | import org.apache.commons.httpclient.methods.PostMethod;
|
| | |
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.util.MoneyBigDecimalUtil;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.jd.JDUtil;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
| | | try {
|
| | | client.executeMethod(pm);
|
| | | String result = pm.getResponseBodyAsString();
|
| | | LogHelper.test("拼多多猜你喜欢:"+result);
|
| | | LogHelper.test("拼多多猜你喜欢:" + result);
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | JSONArray array = json.optJSONArray("data");
|
| | | if (array != null) {
|
| | |
| | | }
|
| | | return null;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 多多进宝爬取数据-品牌好货
|
| | | *
|
| | |
| | | public static PDDGoodsResult getTodaySaleGoods() {
|
| | | JSONObject params = new JSONObject();
|
| | | params.put("type", 1);
|
| | | params.put("sortType",3);
|
| | | |
| | | params.put("sortType", 3);
|
| | |
|
| | | HttpClient client = new HttpClient();
|
| | | PostMethod pm = new PostMethod("https://jinbao.pinduoduo.com/network/api/common/queryTopGoodsList");
|
| | |
| | | return goodsResult;
|
| | | }
|
| | |
|
| | |
|
| | | private static PDDGoodsDetail parseTodaySaleGoods(JSONObject json) {
|
| | | PDDGoodsDetail goods = new PDDGoodsDetail();
|
| | | goods.setMallName(json.optString("mallName"));
|
| | |
| | | if (json.optString("mallId") != null) {
|
| | | goods.setMallId(json.getLong("mallId"));
|
| | | }
|
| | | |
| | |
|
| | | if (json.optString("goodsImageUrl") != null) {
|
| | | goods.setGoodsImageUrl(json.optString("goodsImageUrl"));
|
| | | }
|
| | |
| | | if (json.optString("minGroupPrice") != null) {
|
| | | goods.setMinGroupPrice(json.getLong("minGroupPrice"));
|
| | | }
|
| | | |
| | |
|
| | | if (json.optString("minNormalPrice") != null) {
|
| | | goods.setMinNormalPrice(json.getLong("minNormalPrice"));
|
| | | }
|
| | |
| | |
|
| | | return goods;
|
| | | }
|
| | | |
| | | public static String getPDDGoodsId(String url) {
|
| | |
|
| | | public static String getJDGoodsJS() {
|
| | | InputStream input = JDUtil.class.getClassLoader().getResourceAsStream("pddGoods.js");
|
| | | StringBuilder sb = new StringBuilder();
|
| | | String line;
|
| | | BufferedReader br = new BufferedReader(new InputStreamReader(input));
|
| | | try {
|
| | | if (url.startsWith("https://mobile.yangkeduo.com/goods.html?")
|
| | | || url.startsWith("http://mobile.yangkeduo.com/goods.html?")||url.contains("yangkeduo.com/duo_coupon_landing.html?")) {
|
| | | String preUrl = url.substring(url.indexOf("?") + 1, url.length());
|
| | | String[] sts = preUrl.split("&");
|
| | | for (String st : sts) {
|
| | | if (st.startsWith("goods_id=")) {
|
| | | return st.split("=")[1].trim();
|
| | | }
|
| | | }
|
| | | while ((line = br.readLine()) != null) {
|
| | | sb.append(line);
|
| | | }
|
| | | } catch (IOException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | | static String jdGoodsJs = null;
|
| | | static ScriptEngine engine = null;
|
| | | static {
|
| | | if (jdGoodsJs == null)
|
| | | jdGoodsJs = getJDGoodsJS();
|
| | | ScriptEngineManager manager = new ScriptEngineManager();
|
| | | engine = manager.getEngineByName("javascript");
|
| | | try {
|
| | | engine.eval(jdGoodsJs);
|
| | | } catch (ScriptException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | public static String getPDDGoodsId(String url) {
|
| | |
|
| | | try {
|
| | | if (engine instanceof Invocable) {
|
| | | Invocable in = (Invocable) engine;
|
| | | Object goodsId = in.invokeFunction("getGoodsId", url);
|
| | | if (goodsId!=null)
|
| | | return goodsId.toString().trim();
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | | |
| | | |
| | |
|
| | | }
|