So I'm making a program that extracts the lyrics from a user given song off of AZ Lyrics. The problem I'm having is that after converting the string to a URL, it says Jsoup is not able to parse it because it doesn't accept strings despite the variable being a URL that we are passing in.
String strURL = "http://www.azlyrics.com/lyrics/" + artist + "/" + song + ".html";
URL url = new URL(strURL);
Document doc = Jsoup.parse(url);
What should I do?
I dont know which version of jsoup your are using, but as per latest version the parse method with url alone is not available. You need to pass a timeOut. So try
Document doc = Jsoup.parse(url, 30000);
There is a connect method which would be the best option (IMO). You could pass the stringURL variable directly. Try
Document doc = Jsoup.connect(strURL).get();
If these didn't help check the value of artist and song variables.
You don't need to convert the string strURL
to URL
, this should work:
Document doc = Jsoup.connect("http://www.azlyrics.com/lyrics/" + artist + "/" + song + ".html").timeout(10000).get();
String html = doc.text();
I've set a timeout of 10 seconds, adjust to fit your needs.
You can take a look at the available methods here
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.