【问题标题】:Parse an <div> of an website to web view将网站的 <div> 解析为 webview
【发布时间】:2017-09-02 05:48:43
【问题描述】:

嘿,我试图获取网站的特定部分,然后将其显示在我的 Web 视图中,但问题是当我这样做时,在较小的屏幕上,这些字母都会出现各种错误,带有重音符号之类的东西,我有什么办法吗?可以将网站的特定 div 转移到我的 web 视图中,而不是这个错误的吗? 我在这个网站上需要的部分叫做:“inside2”

这是网站:http://www.dges.gov.pt/guias/detcursopi.asp?codc=8184&code=0400

我加载信息的代码:

   private class MyTask extends AsyncTask<String, Integer, String> {

    // Runs in UI before background thread is called
    @Override
    protected void onPreExecute() {
        super.onPreExecute();



               }

    // This is run in a background thread
    @Override
    protected String doInBackground(String... params) {
        // get the string from params, which is an array

        Bundle CursoInfoData = getIntent().getExtras();

        site = CursoInfoData.getString("site");

        Document doc = null;
        try {
            doc = Jsoup.connect(site).get();
        } catch (IOException e) {
            e.printStackTrace();
        }
         ele = doc.select(".inside2");
        return "start";
    }

    // This is called from background thread but runs in UI
    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);

        // Do things like update the progress bar
    }

    // This runs in UI when background thread finishes
    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        String text = "<html><head>"
                + "<style type=\"text/css\">body{color: #01A9DB; background-color: #FFFFFF;}"
                + "</style></head>"
                + "<body>"
                + ele.toString()
                + "</body></html>";
        cursoInfoWeb.loadData(text, "text/html", "utf-8");


    }

bugged form that I told you

【问题讨论】:

    标签: java android html


    【解决方案1】:

    我猜你有 utf-8 问题。使用这个:

    cursoInfoWeb.loadDataWithBaseURL(null, text, "text/html", "UTF-8", null);
    

    参考:SO answer

    【讨论】:

      猜你喜欢
      • 2012-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 2011-05-26
      • 2015-06-07
      相关资源
      最近更新 更多