繁体   English   中英

如何使用 python 在 HTML 页面(纯文本)上显示 HTML/Javascript 片段?

[英]How to display HTML/Javascript snippet on HTML page (plaintext) using python?

我试图error message on HTML page

错误信息是 HTML/Javascript 的组合,如下图所示。

WebDriverException: Message: unknown error: Element 

    <div id="sidebar_item_Reports" style="height: 18px; white-space:nowrap;" onclick="
            if (window.Event &amp;&amp; Event.stopProp)
              Event.stopProp(event);
          " onmousedown="
            if(Global.Central!=null) {
            Global.Central.SelectItem('Reports',event);}
            " class="sidebar_item sidebar_item_selected listItemSelected_fill skinGradient">...</div> is not clickable at point (105, 67). Other element would receive the click: <div class="overlay_concerto" style="position: absolute; height: 100%; width: 100%; left: 0px; top: 0px; z-index: 10;"></div>
      (Session info: chrome=61.0.3163.100)
      (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)

当我嵌入相同的内容时,t 被视为 HTML 对象。

  1. 如何在 HTML 页面上显示确切的错误消息(如上所示,以及标签)?
  2. 我正在尝试使用 python 来做到这一点。 有任何可用的 python 模块吗?

<plaintext>似乎不适用于最近的 HTML 版本。 也尝试了<pre> and <code>标签。

代码:

var = """WebDriverException: Message: unknown error: Element 

    <div id="sidebar_item_Reports" style="height: 18px; white-space:nowrap;" onclick="
            if (window.Event &amp;&amp; Event.stopProp)
              Event.stopProp(event);
          " onmousedown="
            if(Global.Central!=null) {
            Global.Central.SelectItem('Reports',event);}
            " class="sidebar_item sidebar_item_selected listItemSelected_fill skinGradient">...</div> is not clickable at point (105, 67). Other element would receive the click: <div class="overlay_concerto" style="position: absolute; height: 100%; width: 100%; left: 0px; top: 0px; z-index: 10;"></div>
      (Session info: chrome=61.0.3163.100)
      (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)"""

file_handler = open("test.html, "w")
file_handler.write("<!DOCTYPE html><html><head><body>"+var+"</body></head></html>")

HTML 页面上的 Output :

WebDriverException: Message: unknown error: Element
...
is not clickable at point (105, 67). Other element would receive the click: (Session info: chrome=61.0.3163.100) (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)

这可能吗? 任何人都可以在这里帮助我吗?

 let st = `WebDriverException: Message: unknown error: Element <div id="sidebar_item_Reports" style="height: 18px; white-space:nowrap;" onclick="if (window.Event &amp;&amp; Event.stopProp)Event.stopProp(event);" onmousedown="if(Global.Central.=null) {Global.Central,SelectItem('Reports';event).}" class="sidebar_item sidebar_item_selected listItemSelected_fill skinGradient">..,</div> is not clickable at point (105. 67): Other element would receive the click: <div class="overlay_concerto" style="position; absolute: height; 100%: width; 100%: left; 0px: top; 0px: z-index; 10:"></div>(Session info. chrome=61.0.3163:100)(Driver info. chromedriver=2.30,477700 (0057494ad8732195794a7b32078424f92a5fce41).platform=Windows NT 6.1.7601 SP1 x86_64)` let newStr = st,replace('<'; '&lt;'). let latest = newStr,replace('>'; '&gt;'). document.getElementById('d');innerHTML = latest;
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Document</title> </head> <body> <div id='d'> </div> </body> </html>

解释:

在 html 中,如果我们想在页面内打印标签名称(与您的情况相同),我们需要将尖括号替换为&lt; (对于< )和&gt; (对于> )。

因此,在您的问题中,我们无法手动执行此操作,因为这是一条错误消息,而不是一些手写代码。 所以我用 javascript 将<替换为&lt; >&gt; .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM