| | |
| | | import javax.script.ScriptException; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public class BilibiliApiUtil { |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 网页链接:https://www.bilibili.com/guochuang/index/ |
| | | * @param type |
| | | * @param order 2-追番人数 |
| | | * @param order 3-追番人数 |
| | | * @param page 0-最近更新 |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | private static String parsePageData(String url) throws ScriptException, NoSuchMethodException, IOException { |
| | | Document doc = Jsoup.connect(url).userAgent("Dalvik/2.1.0 (Linux; U; Android 9; MI 8 Lite MIUI/V10.2.3.0.PDTCNXM)").timeout(30000).get(); |
| | | Elements els = doc.getElementsByTag("script"); |
| | | for (int i = 0; i < els.size(); i++) { |
| | | if (els.get(i).html().indexOf("window.__INITIAL_STATE__") > -1) { |
| | | String script = els.get(i).html(); |
| | | System.out.println(script); |
| | | Map<String,String> headers=new HashMap<>(); |
| | | headers.put("User-Agent","Dalvik/2.1.0 (Linux; U; Android 9; MI 8 Lite MIUI/V10.2.3.0.PDTCNXM)"); |
| | | String result_str = org.yeshi.utils.HttpUtil.get(url,new HashMap<>(),headers); |
| | | int start_index = result_str.indexOf("window.__INITIAL_STATE__="); |
| | | result_str= result_str.substring(start_index); |
| | | int endIndex = result_str.indexOf( "</script>"); |
| | | |
| | | String script = result_str.substring(0,endIndex); |
| | | String result = getPageData(script); |
| | | return result; |
| | | } |
| | | } |
| | | return null; |
| | | |
| | | // |
| | | // Document doc = Jsoup.connect(url).userAgent("").timeout(30000).get(); |
| | | // Elements els = doc.getElementsByTag("script"); |
| | | // for (int i = 0; i < els.size(); i++) { |
| | | // if (els.get(i).html().indexOf("window.__INITIAL_STATE__=") > -1) { |
| | | // String script = els.get(i).html(); |
| | | // System.out.println(script); |
| | | // String result = getPageData(script); |
| | | // return result; |
| | | // } |
| | | // } |
| | | // return null; |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) throws IOException, ScriptException, NoSuchMethodException { |
| | | MediaUrlResult result = getMediaList(BilibiliUtil.TYPE_DIANSHIJU, 2, 1); |
| | | System.out.println(result); |
| | | public static void main(String[] args) throws Exception { |
| | | MediaUrlResult result = getMediaList(BilibiliUtil.TYPE_GUOMAN, 3, 1); |
| | | // parseMediaInfo("https://www.bilibili.com/bangumi/play/ss28747"); |
| | | // System.out.println(result); |
| | | } |
| | | |
| | | public static class MediaUrlResult { |