简体   繁体   中英

How to read/parse article content from link to string

I was in need of help. How do I get content on article websites with java or android?

You can try http://jsoup.org/

Use it to fetch the page from link and parse the content.

Well, here is a sample,

String url = "http://inet.detik.com/read/2012/12/12/105558/2116258/796/produktif-kerja-mobile-dengan-samsung-ativ-smart-pc-yang-revolusioner";
Document doc = Jsoup.connect(url).timeout(20000).get();
Elements elements = doc.select("div[class=text_detail]");
if (elements.size() > 0) {
    System.out.println(elements.text());
}

The above code just print outs the entire text. If you want to get a pretty print version, you need to handle some html tags (such as br) by yourself. You can easily visit the html tags with jsoup, so just spend some time on the documents and write the code on your own.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM