Grab jobs from oDesk
- Create LinkEntry class as following
- Create oDesk class as following
- Call oDesk.grab() method as following
Call oDesk.grab() method
List<LinkEntry> links = oDesk.grab(); for (int i = 0; i < links.size(); i++) { logger.info("\r\n(" + (i + 1) + ")\r\n" + links.get(i).toString()); }LinkEntry class
public class LinkEntry { public String url = ""; public String title = ""; public String desc = ""; public String toString() { String tag = "\r\n"; tag += "Url: " + url + "\r\n"; tag += "Title: " + title + "\r\n"; tag += "Desc: " + desc + "\r\n"; return tag; } }oDesk class
public class oDesk { public static List<LinkEntry> grab() { List<LinkEntry> tag = new ArrayList<LinkEntry>(); try { String link = "https://www.odesk.com/api/profiles/v1/search/jobs.xml?page=0;50&sort=date_posted;D"; Document doc = Jsoup.parse(new URL(link), 60000); Elements elements = doc.select("job"); Element element = null; for (int i = 0; i < elements.size(); i++) { element = elements.get(i); LinkEntry job = new LinkEntry(); if (element.select("ciphertext").first() == null) continue; job.url = "https://www.odesk.com/jobs/" + element.select("ciphertext").first().text(); job.title = element.select("op_title").first().text(); job.desc = element.select("op_description").first().text(); tag.add(job); } } catch (Exception e) { logger.error("", e); } return tag; } }
No comments:
Post a Comment