Display a part of the webpage on the webview android

前端 未结 3 640
南笙
南笙 2020-11-29 06:08

I want to make an app which loads the content from the webpage into webview. I want to show only a particular thing in the entire webview, not the whole content of the webpa

3条回答
  •  盖世英雄少女心
    2020-11-29 06:53

    check Jsoup it provides an library which gives an easy way of extracting Html elements from a webpage

    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(url.toURI());
    HttpResponse resp = client.execute(get);
    
    String content = EntityUtils.toString(resp.getEntity());
    Document doc = Jsoup.parse(content);
    Elements ele = doc.select("div.classname");
    

    This example executes an Http GET and then extracts an Div element with the class "classname" which you can then load in your webview

提交回复
热议问题