package jsoupTest;
import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;
import org.jsoup.Connection.Method;import org.jsoup.Connection.Respe;import org.jsoup.Jsoup;
public class JsoupTest { public static void main(String[] args) throws IOException { Map<String, String> map = new HashMap<>(); //map.put请根据自己的微博cookie得到
Respe res = Jsoup.connect("http://weibo.com/u/别人的主页id") .cookies(map).method(Method.GET).execute(); String s = res.body(); System.out.println(s); String[] ss = s.split("<script>FM.view"); int i = 0; List<String> list = new ArrayList<>(); for (String x : ss) { if (x.contains("\"html\":\"")) { String value = getHtml(x); list.add(value); System.out.println(value); }
} }
public static String getHtml(String s) { String content = s.split("\"html\":\"")[1] .replaceAll("(\\\\t|\\\\n|\\\\r)", "") .replaceAll("\\\\\"", "\"") .replaceAll("\\\\/", "/"); content = content.substring(0, content.length() <= 13 ? content.length() : content.length() - 13); return Native2AsciiUtils.ascii2Native(content); }}
|