Skip to content

Instantly share code, notes, and snippets.

@ajpelaez
Last active February 23, 2016 13:24
Show Gist options
  • Save ajpelaez/4c1e190ba17da48ee23d to your computer and use it in GitHub Desktop.
Save ajpelaez/4c1e190ba17da48ee23d to your computer and use it in GitHub Desktop.
/*
The MIT License (MIT)
Copyright (c) 2016 sinfonier-project
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package com.sinfonier.bolts;
import java.util.List;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.TreeMap;
import java.util.HashMap;
import java.util.Map;
import java.net.URL;
import java.net.URLEncoder;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Document;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
public class LinkedinGetJobOfferInfo extends BaseSinfonierBolt {
// Class variables
private String link;
private String companyNamee;
// Must implement constructor. Do not touch
public LinkedinGetJobOfferInfo(String xmlFile) {
super(xmlFile);
}
@Override
public void userprepare() {
this.link = this.getParam("url");
}
@Override
public void userexecute() {
try{
URL url = new URL((String) this.getField(this.link));
InputStream is = url.openStream();
int ptr = 0;
StringBuilder builder = new StringBuilder();
while ((ptr = is.read()) != -1) {
builder.append((char) ptr);
}
try{
String html = builder.toString();
Document document = Jsoup.parse(html);
Element interestingParts = document.getElementById("decoratedJobPostingModule");
String str = interestingParts.toString();
Element interestingParts2 = document.getElementById("topCardV2Module");
String str2 = interestingParts2.toString();
String company = StringUtils.substringBetween(str, "\"companyName\":\"", "\"");
//System.out.println("Company:" + company);
this.addField("company",company);
String description = StringUtils.substringBetween(str, "\"rawText\":\"", "\"");
//System.out.println("Description:" + description);
this.addField("description",description);
String location = StringUtils.substringBetween(str, "\"formattedLocation\":\"", "\"");
//System.out.println("Location:" + location);
this.addField("location",location);
String companylink = StringUtils.substringBetween(str2, "\"companyPageNameLink\":\"", "\"");
//System.out.println("Company Link:" + companylink);
this.addField("companylink",companylink);
this.emit();
} catch (Exception e) {
this.addField("Error finding the information",e.toString());
}
}
catch (Exception e) {
this.addField("Url dont exits",e.toString());
}
// Por si acaso, que emita (puede que no haya links)
this.emit();
}
public void usercleanup() {
}
}
@evasuarez22
Copy link

NO -->URL url = new URL((String) this.getField("url"));
SI --> URL url = new URL((String) this.getField(this.link));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment