| | |
| | | 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 {
|
| | |
|
| | |
| | | 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;
|
| | | }
|
| | | }
|