我正在Android WebView中使用显示字符串HTML挣扎。
在服务器端,我下载了一个网页并转义了HTML字符和引号(我使用了Python):
my_string = html.escape(my_string, True)
在Android客户端上:字符串不通过以下方式转义:
myString = StringEscapeUtils.unescapeHtml4(myString)
webview.loadData( myString, "text/html", "encoding");
但是,webview只是将它们显示为文字字符串。结果如下:
编辑:我添加从服务器端返回的原始字符串:
链接rel =“ apple-touch-icon”;尺寸=“ 114x114” href =“&quot; /static/favicon/apple-touch-icon-114x114.png”&gt; &lt; link rel =“苹果触摸图标”;尺寸=“ 72x72” href =“&quot; /static/favicon/apple-touch-icon-72x72.png”&gt; &lt; link rel =“苹果触摸图标”;尺寸=“ 144x144” href =“&quot; /static/favicon/apple-touch-icon-144x144.png”&gt; &lt; link rel =“苹果触摸图标”;尺寸=“ 60x60” href =“&quot; /static/favicon/apple-touch-icon-60x60.png”&gt; &lt; link rel =“苹果触摸图标”;尺寸=“ 120x120” href =“&quot; /static/favicon/apple-touch-icon-120x120.png”&gt; &lt; link rel =&quot; 苹果触摸图标” 尺寸=“ 76x76” href =“&quot; /static/favicon/apple-touch-icon-76x76.png”&gt; &lt; link rel =“苹果触摸图标”;尺寸=“ 152x152” href =“&quot; /static/favicon/apple-touch-icon-152x152.png”&gt; &lt; link rel =“苹果触摸图标”;尺寸=“ 180x180” href =“&quot; /static/favicon/apple-touch-icon-180x180.png”&gt; &lt; link rel =“ icon”;type =“ image / png” href =“&quot; /static/favicon/favicon-192x192.png” 尺寸=“ 192x192” &lt; link rel =“ icon”;type =“ image / png” href =“&quot; /static/favicon/favicon-160x160.png” 尺寸=“ 160x160” &lt; link rel =&quot; 图标” type =“ image / png” href =“&quot; /static/favicon/favicon-96x96.png” 尺寸=“ 96x96” &lt; link rel =“ icon”;type =“ image / png” href =“&quot; /static/favicon/favicon-16x16.png” 尺寸=“ 16x16” &lt; link rel =“ icon”;type =“ image / png” href =“&quot; /static/favicon/favicon-32x32.png” 尺寸=“ 32x32” &lt;元名称=“ msapplication-TileColor”;内容=“#da532c” &lt;元名称=“ msapplication-TileImage”;content =“ / static / favicon / mstile-144x144.png” &lt;元名称=“ msapplication-config”;内容=“ / static / favicon / browserconfig.xml”;&gt; &lt;!-外部CSS-&gt; &lt; link rel =“ stylesheet” href =&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css&quot; &lt;!-外部字体-&gt; &lt; link href =” // maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css” rel =“ stylesheet” &lt; link href =&#x27; // fonts.googleapis.com/css?family=Open+Sans:300,600' rel =&#x27; stylesheet&#x27; type =&#x27; text / css&#x27;&gt; &lt; link href =&#x27; // fonts.googleapis.com/css?family=Lora:400,700' rel =&#x27; stylesheet&#x27; type =&#x27; text / css&#x27;&gt; &lt;!-[如果是IE 9]&gt; &lt; script src =” // cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js”</script> &lt; script src =” // cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js”&lt; / script&gt; &lt ;! [endif]-&gt; &lt;!-网站CSS-&gt; &lt; link rel =“ stylesheet” type =“ text / css”;href =“&quot; /static/css/style.css”&gt; &lt; link rel =“ stylesheet” type =“ text / css”;href =“&quot; /static/css/glyphicon.css”&gt; &lt; / head&gt; &lt; body&gt; &lt; div class =“容器文章-页面”&gt; &lt; div class =“ row”&gt; &lt; div class =“ col-md-8 col-md-offset-2”&gt; &lt; h2&gt;&lt; a href =&quot; quot; href =“&quot; /static/css/glyphicon.css”&gt; &lt; / head&gt; &lt; body&gt; &lt; div class =“容器文章-页面”&gt; &lt; div class =“ row”&gt; &lt; div class =“ col-md-8 col-md-offset-2”&gt; &lt; h2&gt;&lt; a href =&quot; quot; href =“&quot; /static/css/glyphicon.css”&gt; &lt; / head&gt; &lt; body&gt; &lt; div class =“容器文章-页面”&gt; &lt; div class =“ row”&gt; &lt; div class =“ col-md-8 col-md-offset-2”&gt; &lt; h2&gt;&lt; a href =&quot;http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html&quot;&gt ; Gov。杰里·布朗(Jerry Brown)说特德·克鲁兹(Ted Cruz)绝对不适合(&#39;)因气候变化而竞选公职的观点&lt; / a&lt; / h2&gt; &lt; h4&gt; Sam Levine&lt; / h4&gt; &lt; div class =“ article”&gt; 加利福尼亚州州长杰里·布朗(D)星期天说,德克萨斯州参议员特德·克鲁兹(R-Texas)“绝对不适合竞选公职”。因为他在气候变化方面的立场。&lt; p&gt;&quot;我刚从新罕布什尔州回来,那里到处都是冰雪。我对此的看法很简单:有关此事的辩论应遵循科学并应遵循数据,而且许多关于全球变暖的警报者,他们有一个问题,因为科学不支持他们。克鲁兹&lt; a href =&quot;https://www.youtube.com/watch?v=m0UJ_Sc0Udk&lt ; said&lt; / a&gt; 在“与塞思·迈耶斯晚晚”上 &lt; / p&gt; &lt; p&gt;为了支持他的主张,克鲁兹引用了卫星数据,该数据显示在过去的17年中没有明显的变暖现象。但是Cruz的推理&lt; a href =&quot; http://www.politifact.com/truth-o-meter/statements/2015/mar/20 / ted-cruz / ted-cruzs-worlds-fire-not-last-17-years /“已被由Politifact揭穿,这表明科学家有足够的证据相信气候将继续变暖。&lt; p&gt;&quot;他所说的话绝对是错误的,“布朗在&lt; a href =&quot; http://www.nbcnews。 “不适合运行” n328046”“ NBC新闻”。他补充说&lt; a href =&quot; http://climate.nasa.gov/scientific-consensus/ “超过90%”。研究气候的科学家们一致认为,气候变化是人类活动造成的。“那个人象征着这种无知和对现有科学数据的直接伪造。令人震惊,我认为男人已经使自己完全不适合竞选公职。” 布朗说。&lt; p&gt;布朗补充说,气候变化具有&lt; a href =&quot; http://www.huffingtonpost.com/2015/03/06/california-drought-february- record_n_6820704.html?utm_hp_ref =加利福尼亚干旱“导致他所在州的干旱,以及东海岸的严寒和暴风雨。&lt; p&gt;虽然克鲁兹可能在新罕布什尔州到处都看到冰雪,但数据显示该国实际上正在经历&lt; a href =&quot; http://www.huffingtonpost.com/2015/02/19/cold-weather- winter_n_6713104.html“&gt;比平均水平&lt; / a&gt; / p。&lt; p&gt;布朗对克鲁兹的批评发生在得克萨斯州参议员被宣布宣布&lt; a href =&quot; http://www.huffingtonpost.com/2015/03/22/ted-cruz-2016_n_6917824.html" 总统竞选&lt; / a&gt;。&lt; / p&gt; &lt; / div&gt; &lt; div class =“原始”&gt; &lt; a href =&quot;http://www.huffingtonpost.com/2015/03/22/ted-cruz-climate-change_n_6919002.html&lt; VIEW ORIGINAL&lt; / a&gt; &lt; / div&gt; &lt; / div&gt; &lt; / div&gt; &lt; / div&gt; &lt; script src =” // code.jquery.com/jquery-latest.js”</script &lt; script src =” / static / js / modal.js”&lt; / script &lt; script src =&quot; /static/js/bootbox.min.js"&lt; / script&gt; &lt; script src =” / static / js / site.js”&lt; / script &lt; script&gt; (function(i,s,o,g,r,a,m){i [&#x27; GoogleAnalyticsObject&#x27;] = r; i [r] = i [r] || function(){(i [ r] .q = i [r] .q || [])。push(arguments)},i [r] .l = 1 * new Date(); a = s.createElement(o),m = s。 getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a,m)})(窗口,文档,&#x27; script&#x27;,&#x27; //万维网。google-analytics.com/analytics.js','ga'); ga(&#x27; create&#x27;,&#x27; UA-56257533-1&#x27;,&#x27; auto&#x27;);ga(&#xsend&#x27 ;,&#x27; pageview&#x27;); &lt; / script&gt; &lt; / body&gt; &lt; / html&gt;”