JSONP示例

2016/12/26 15:54
阅读数 24
package com.common.util;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class JsoupUtil {
  public static void main(String[] args) {
    List<String> urlList = new ArrayList<String>();
    for (int i = 1; i < 9; i++) {
      try {
        Document doc = JsoupUtil.getJsoupDoc("https://www.aa187.com/htm/vodlist1/" + i + ".htm");
        // 获取所有的详情页的地址
        //dy_list -> ul -> li -> a[href]
        Elements aElements = doc.select(".dy_list ul li a");
        if (aElements != null && aElements.size() > 0) {
          for (Element a : aElements) {
            String detailUrl = a.attr("href");
            Document detailDoc = JsoupUtil.getJsoupDoc("https://www.aa187.com/" + detailUrl);
            Element element = detailDoc.getElementById("dyplayer");
            Elements videoElement = element.getElementsByTag("script");
            String src = videoElement.html();
            String preFix = "http://kele.bb149.com/vod_water/";
            String lastAddr = preFix + src.substring(41, src.lastIndexOf("mp4") + 3) + "\n";
            System.out.println(lastAddr);
            urlList.add(lastAddr);
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
        continue;
      }
    }
    try {
      FileUtils.writeLines(new File("E:/呵呵.txt"), urlList, true);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public static Document getJsoupDoc(String url) throws Exception {
    Document doc = Jsoup.connect(url).timeout(10000) // 设置连接超时时间
        .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31").get();
    return doc;
  }
}

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部