【问题标题】:How to get innerHTML from webview in android如何从android中的webview获取innerHTML
【发布时间】:2017-11-08 17:14:08
【问题描述】:

您好,我整天都在搜索互联网和 stackoverflow,但没有任何解决方案! :(

我的问题是:

我必须在应用程序中显示一些时间表,并且数据存储在网页上,通常在PC上您访问该页面,输入您的ID,它会显示时间表......

但是我如何在不与 webview 或类似的东西交互的情况下完成日程安排?我必须在登录后保存一些特定的 html 数据...

我已经厌倦了jsoup,但是登录后,url改变了,我不知道如何获取它,因此我尝试了webview,但这也不起作用

请帮忙:)

【问题讨论】:

标签: android html webview


【解决方案1】:

公共类 getHTML 扩展 AsyncTask{

   String words;

   @Override
   protected Void doInBackground(Void... params) {

       try {
           final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";
           final String FORM_URL = "http://timetable.scitech.au.dk/apps/skema/VaelgElevskema.asp?webnavn=skema";
           final String SCHEDULE_URL = "http://timetable.scitech.au.dk/apps/skema/ElevSkema.asp";
           final String USERID = "201506426";

            // # Go to search page
           Connection.Response loginFormResponse = Jsoup.connect(FORM_URL)
                   .method(Connection.Method.GET)
                   .userAgent(USER_AGENT)
                   .execute();

            // # Fill the search form
           FormElement loginForm = (FormElement)loginFormResponse.parse()
                   .select("form").first();

            // ## ... then "type" the id ...
           Element loginField = loginForm.select("input[name=aarskort]").first();
           loginField.val(USERID);



            // # Now send the form
           Connection.Response loginActionResponse = loginForm.submit()
                   .cookies(loginFormResponse.cookies())
                   .userAgent(USER_AGENT)
                   .execute();

            // # go to the schedule
           Connection.Response someResponse = Jsoup.connect(SCHEDULE_URL)
                   .method(Connection.Method.GET)
                   .userAgent(USER_AGENT)
                   .execute();

           // # print out the body
           Element el = someResponse.parse()
                   .select("body").first();

            words = el.text();


           System.out.println(loginActionResponse.parse().html());


       } catch (IOException e) {
           e.printStackTrace();
       }
        return null;
   }


   @Override
   protected void onPostExecute(Void aVoid) {
       super.onPostExecute(aVoid);


       tv.setText(words);

       Toast.makeText(MainActivity.this, "DET VIRKER!", Toast.LENGTH_SHORT).show();

   }

}

【讨论】:

  • 这是我现在所拥有的,它不起作用。我认为这可能与饼干有关?如果你们想知道它应该返回什么,然后转到 FORM_URL,然后粘贴这个:201506426,然后它会显示时间表.. 抱歉英语不好:D
  • 当我运行我的代码时,它返回:“Tilmeldinger for Missing parameter”
猜你喜欢
  • 2014-03-04
  • 1970-01-01
  • 2014-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-23
  • 2011-03-18
  • 1970-01-01
相关资源
最近更新 更多