0

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;
    }
});
asyaben
  • 55
  • 2
  • 8
  • Do you mean you log in your student account in your browser and then run the program? – Adam Lyu Mar 20 '16 at 14:14
  • No, I added my java code above now its more clearly understandable. I mean when the user open the transcript from the webview of application. – asyaben Mar 20 '16 at 17:33
  • Code snippets are meant to be used with code which can be run by browser like HTML/CSS/JavaScript. Java is not same as JavaScript so don't use it here. Instead use *code sample* (`{}` icon in editors menu) to let Stack Overflow apply proper formatting for your code (like color for keywords). – Pshemo Mar 20 '16 at 17:45
  • Ok, i changed it thanks for the tip. – asyaben Mar 20 '16 at 18:01

2 Answers2

1

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.

statosdotcom
  • 3,109
  • 2
  • 17
  • 40
0

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();
Pshemo
  • 122,468
  • 25
  • 185
  • 269
  • Also make sure that this URL is correct or that site is online. – Pshemo Mar 20 '16 at 14:22
  • Thank for reply Pshemo. I changed the code as you said but it again gives the html of https://campus.bk.edu.da not the student_trans. I added my java code above too, may be the error is in my webview code.Can you check please? – asyaben Mar 20 '16 at 17:35
  • @asyaben To be honest I can't access site from your url. I can't even visit campus.bk.edu.da server so can't help you much. – Pshemo Mar 20 '16 at 17:47
  • @asyaben for now I suspect that you didn't let jsoup to login to your account which is causing server to not recognize you and redirects you to main site. For more information about logging using jsoup visit http://stackoverflow.com/questions/6432970/jsoup-posting-and-cookie – Pshemo Mar 20 '16 at 17:56
  • "I written the link as an example" I know, I meant that without seeing real URL I can't help you much :). Anyway I am not sure why you wan to "get the values enterred to editText". If you want to login you need to *put* these values there, or to be more precise *send* these values to page which will handle authentication and will give you cookies describing session (based on form action attribute it looks like you need to send `id` and `pass` to `https://campus1.isikun.edu.tr/checkpass.asp`). Visit question linked in my previous comment to see how to send these values. – Pshemo Mar 20 '16 at 18:34