- package test;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- public class ShenZuiYou{
- private static int currentPage=0;
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- System.out.println("Please input the page:");
- BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));
- String temp;
- while (true) {
- temp=buff.readLine();
- if(temp.trim().equals("")){
- System.out.println("--------您输入空字符,将默认加载下一页:"+(++currentPage)+"-----------\\n");
- }else{
- currentPage=Integer.parseInt(temp.trim());
- }
- // Scanner sc = new Scanner(System.in);
- System.out.println(getUrl(currentPage));
- }
- }
- private static String getUrl(int page) {
- StringBuffer sb = new StringBuffer();
- try {
- String url = "http://hot.weibo.com/?v=6399&count=45&page=" + page
- ;
- Document doc = Jsoup
- .connect(url)
- .timeout(60000)
- .userAgent(
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:23.0) Gecko/20100101 Firefox/23.0")
- .get();
- Elements newsHeadlines = doc.select("div.WB_text");
- int i = 1;
- for (Element e : newsHeadlines) {
- String text = e.text();
- sb.append(text.substring(text.lastIndexOf("@")));
- // sb.append(text);
- if(i > 0)
- {
- sb.append("\\n ↑
- //该片段来自于http://www.codesnippet.cn/detail/1612201411286.html
来源: http://www.codesnippet.cn/detail/1612201411286.html