asyaben
asyaben

Reputation: 55

JSOUP- cannot parse relative URL

I'm really new on JSOUP and I'm developing an course selection android project.It goes the college web site by using a webview. Student logs on the system, then the project must parse the student transcript.

college web site for instance: www.campus.bk.edu.da

Student transcript URL is: www.campus.bk.edu.da/student_trans

my code is below; I am running this code after user logged in to site.

 String ht ="";
String url = "https://campus.bk.edu.da/student_trans.asp";
Document doc =Jsoup.parse(url);
ht=doc.html();

When I run this I got the html of the paren site; www.campus.bk.edu.da. Where am i doing wrong?

My java code is:

campusWeb.loadUrl("http://campus.bk.edu.da/");

campusWeb.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        if (url.toString().equals("https://campus.bk.edu.da/student_trans.asp")) {
            new soup().execute();
        }
        return true;
    }
});

Upvotes: 0

Views: 347

Answers (2)

Pshemo
Pshemo

Reputation: 124295

Jsoup.parse method is trying to parse posted HTML code (or its fragment) into DOM, but problem is that you didn't post HTML but URL. Because if that as result you got DOM which contains

<html>
 <head></head>
 <body>
  https://campus.bk.edu.da/student_trans.asp
 </body>
</html>

If you want to get Document representing HTML code from provided URL you first need to connect to it. So try with

Document doc = Jsoup.connect(url).get();

Upvotes: 0

Probably you're getting a redirect to root url called by a 404 (file not found) error, because https://campus.bk.edu.da/student_trans.asp doesn't ehxist, but https://campus.bk.edu.da/student_trans , i.e., without dot asp at the end.

Upvotes: 1

Related Questions