jhy / jsoup

jsoup: the Java HTML parser, built for HTML editing, cleaning, scraping, and XSS safety.
https://jsoup.org
MIT License
10.94k stars 2.19k forks source link

JSoup Malformed URL Exception #1051

Closed arun131700 closed 6 years ago

arun131700 commented 6 years ago

0 down vote favorite I am trying to use JSoup to open a list of links I've stored in an ArrayList named arrayLinks. When I run the code to open a link in the ArrayList, I get a Malformed URL Exception.However, if I take the Malformed Links and hardcode them into the application, I get no errors. I have tried looking at several other posts using StringFormatters or UTF-8, but nothing seems to work. Any suggestions would be greatly appreciated. Thanks!

Code that Doesn't Work:

article = Jsoup.connect(arrayLinks.get(i)).get()

Error:

Caused by: java.net.MalformedURLException: no protocol: "https://www.sbnation.com/college-football-recruiting/2014/7/3/5715252/cordell-broadus-recruit-scouting-report-sure-handed-receiver"
at java.base/java.net.URL.<init>(URL.java:627)
at java.base/java.net.URL.<init>(URL.java:523)
at java.base/java.net.URL.<init>(URL.java:470)
at org.jsoup.helper.HttpConnection.url(HttpConnection.java:132)

Code that Works:

article = Jsoup.connect("https://www.sbnation.com/college-football-recruiting/2014/7/3/5715252/cordell-broadus-recruit-scouting-report-sure-handed-receiver").get()

There seems to be an error in the way that JSoup is processing the entries of the ArrayList.

jhy commented 6 years ago

Please don't cross post from Stack Overflow. You have good answers there (and obviously this is not a jsoup bug so shouldn't be here)