Snippets

Lars Genius.com: profile to ID

Created by Lars
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;

public class ProfileToIDParser {

	public static int parse(String username) {
		try {
			String url = "https://genius.com/" + username;
			org.jsoup.nodes.Document document = Jsoup.connect(url).get();
			
			//returns the relative resource path, e.g. /users/12345; .first() may be omitted
			Element resourcePath = document.head().select("meta[name=newrelic-resource-path]").first();
			
			//Extract the Genius user ID
			String id = resourcePath.attr("content").replace("/users/", "");
		
			return Integer.parseInt(id);
	
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0;
	}
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.