package com.putera.kamus; /** * Created with IntelliJ IDEA. * User: Syahmi * Date: 16/11/2013 * Time: 3:29 * To change this template use File | Settings | File Templates. */ public class Kamus { public static void main(String[] args) { Scraper scraper = new Scraper(); for (String arg : args) { String data[] = scraper.get(arg); if (data == null) { System.out.println("Ralat"); return; } for (String s : data) { System.out.println(s); } } } }
package com.putera.kamus; import org.jsoup.Jsoup; import org.jsoup.nodes.*; import java.net.URL; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Iterator; /** * Created with IntelliJ IDEA. * User: Syahmi * Date: 16/11/2013 * Time: 3:35 * To change this template use File | Settings | File Templates. */ public class Scraper { private static final String QUERY_URL = "http://prpm.dbp.gov.my/Search.aspx?k="; public String[] get(String word) { URL url; ArrayList<String> list = new ArrayList<String>(); try { url = new URL(QUERY_URL + URLEncoder.encode(word, "UTF-8")); Document doc = Jsoup.parse(url, 30000); String resp = ""; Iterator<Element> it = doc.select(".alternate").iterator(); while(it.hasNext()) { Element e = it.next(); list.add(e.text()); } String[] array = list.toArray(new String[list.size()]); return array; } catch (Exception e) { String[] error = new String[1]; error[0] = e.getMessage(); return error; } } }
0 ulasan:
Catat Ulasan
Selamat datang ke 0x2013LΣΣT. Sekiranya anda mempunyai persoalan, pandangan, permintaan, bantuan, cadangan dan sebagainya. Tinggalkan pesanan anda ke dalam kotak komen. Terima kasih !
- http://0x2013.blogspot.com -