| | |
| | | }
|
| | | return null;
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 多多进宝爬取数据-品牌好货
|
| | | * |
| | | * @param sf
|
| | | * @return
|
| | | */
|
| | | public static PDDGoodsResult getTodaySaleGoods() {
|
| | | JSONObject params = new JSONObject();
|
| | | params.put("type", 1);
|
| | | params.put("sortType",3);
|
| | | |
| | |
|
| | | HttpClient client = new HttpClient();
|
| | | PostMethod pm = new PostMethod("https://jinbao.pinduoduo.com/network/api/common/queryTopGoodsList");
|
| | | pm.setRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko");
|
| | | pm.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
|
| | | pm.setRequestHeader("Referer", "https://jinbao.pinduoduo.com/promotion/hot-promotion");
|
| | | pm.setRequestBody(params.toString());
|
| | |
|
| | | PDDGoodsResult goodsResult = null;
|
| | |
|
| | | try {
|
| | | client.executeMethod(pm);
|
| | | String result = pm.getResponseBodyAsString();
|
| | | JSONObject json = JSONObject.fromObject(result);
|
| | | Boolean code = json.optBoolean("success");
|
| | | if (code != null && code) {
|
| | | JSONObject root = json.optJSONObject("result");
|
| | | if (root == null) {
|
| | | return null;
|
| | | }
|
| | | JSONArray array = root.optJSONArray("list");
|
| | | if (array == null) {
|
| | | return null;
|
| | | }
|
| | |
|
| | | List<PDDGoodsDetail> goodsList = new ArrayList<PDDGoodsDetail>();
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | PDDGoodsDetail parseGoods = parseTodaySaleGoods(array.getJSONObject(i));
|
| | | if (parseGoods != null) {
|
| | | goodsList.add(parseGoods);
|
| | | }
|
| | | }
|
| | | int totalCount = root.optInt("total");
|
| | |
|
| | | goodsResult = new PDDGoodsResult();
|
| | | goodsResult.setGoodsList(goodsList);
|
| | | goodsResult.setTotalCount(totalCount);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | return goodsResult;
|
| | | }
|
| | |
|
| | |
|
| | | private static PDDGoodsDetail parseTodaySaleGoods(JSONObject json) {
|
| | | PDDGoodsDetail goods = new PDDGoodsDetail();
|
| | | goods.setMallName(json.optString("mallName"));
|
| | | goods.setMerchantType(json.optInt("merchantType"));
|
| | | goods.setGoodsId(json.optLong("goodsId"));
|
| | | goods.setGoodsName(json.optString("goodsName"));
|
| | | goods.setGoodsDesc(json.optString("goodsDesc"));
|
| | | goods.setSalesTip(json.optString("salesTip"));
|
| | |
|
| | | if (json.optString("mallId") != null) {
|
| | | goods.setMallId(json.getLong("mallId"));
|
| | | }
|
| | | |
| | | if (json.optString("goodsImageUrl") != null) {
|
| | | goods.setGoodsImageUrl(json.optString("goodsImageUrl"));
|
| | | }
|
| | |
|
| | | if (json.optString("goodsThumbnailUrl") != null) {
|
| | | goods.setGoodsThumbnailUrl(json.optString("goodsThumbnailUrl"));
|
| | | }
|
| | |
|
| | | if (json.optString("minGroupPrice") != null) {
|
| | | goods.setMinGroupPrice(json.getLong("minGroupPrice"));
|
| | | }
|
| | | |
| | | if (json.optString("minNormalPrice") != null) {
|
| | | goods.setMinNormalPrice(json.getLong("minNormalPrice"));
|
| | | }
|
| | |
|
| | | if (json.optString("categoryId") != null) {
|
| | | goods.setCategoryId(json.getLong("categoryId"));
|
| | | }
|
| | |
|
| | | goods.setCategoryName(json.optString("categoryName"));
|
| | | goods.setHasCoupon(json.optBoolean("hasCoupon"));
|
| | |
|
| | | if (json.optString("couponMinOrderAmount") != null) {
|
| | | goods.setCouponMinOrderAmount(json.getLong("couponMinOrderAmount"));
|
| | | }
|
| | |
|
| | | if (json.optString("couponDiscount") != null) {
|
| | | goods.setCouponDiscount(json.getLong("couponDiscount"));
|
| | | }
|
| | |
|
| | | if (json.optString("couponTotalQuantity") != null) {
|
| | | goods.setCouponTotalQuantity(json.getLong("couponTotalQuantity"));
|
| | | }
|
| | |
|
| | | if (json.optString("couponRemainQuantity") != null) {
|
| | | goods.setCouponRemainQuantity(json.getLong("couponRemainQuantity"));
|
| | | }
|
| | |
|
| | | if (json.optString("couponStartTime") != null) {
|
| | | goods.setCouponStartTime(json.getLong("couponStartTime"));
|
| | | }
|
| | |
|
| | | if (json.optString("couponEndTime") != null) {
|
| | | goods.setCouponEndTime(json.getLong("couponEndTime"));
|
| | | }
|
| | |
|
| | | if (json.optString("promotionRate") != null) {
|
| | | goods.setPromotionRate(json.getLong("promotionRate"));
|
| | | }
|
| | |
|
| | | if (json.optString("optId") != null) {
|
| | | goods.setOptId(json.getLong("optId"));
|
| | | }
|
| | |
|
| | | return goods;
|
| | | }
|
| | | }
|