Android JSoup使用site-css来提取div类



我目前正在开发一个应用程序,该应用程序显示网页的一个div类。问题是,这个div类(当然(不再使用站点的CSS了。不,我想将CSS添加回显示的div类。但我该怎么做呢?

以下是我显示"事件"div的代码:

    private class  LoadData extends AsyncTask<Void,Void,Void>
{
    String html=new String();
    Document doc = null;
    Elements ele = null;
    @Override
    protected Void doInBackground(Void... params) {
        try {
            doc = Jsoup.connect(URL).timeout(100000).get();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Elements ele = doc.select("div.events");
        html = ele.toString();
        return null;
    }
    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        String mime = "text/html";
        String encoding = "utf-8";
        myWebView.loadData(html, mime, encoding);
    }
}

您可以使用jsoup获取"style"或"link"标记,并将其前置到html数据。

最新更新