小编use*_*743的帖子

如何摆脱python中的ascii编码错误

string = "Deepika Padukone, Esha Gupta or Yami Gautam - Who's looks hotter and sexier? Vote! - It's ... Deepika Padukone, Esha Gupta or Yami Gautam…. Deepika Padukone, Esha Gupta or Yami Gautam ... Tag: Deepika Padukone, Esha Gupta, Kalki Koechlin, Rang De Basanti, Soha Ali Khan, Yami  ... Amitabh Bachchan and Deepika Padukone to be seen in Shoojit Sircar's Piku ..."

fp = open("test.txt", "w+");

fp.write("%s" %string);
Run Code Online (Sandbox Code Playgroud)

运行上面的代码后,我得到以下错误.

File "encode_error.py", line 1

SyntaxError: Non-ASCII character '\xe2' in file encode_error.py …
Run Code Online (Sandbox Code Playgroud)

python

5
推荐指数
2
解决办法
1万
查看次数

如何使用javascript查找和替换HTML DOM元素中的字符串

我试图替换字符串的出现次数"blue""red"使用DOM方法在文档中。但是,我没有得到想要的结果。

这是我试过的代码:

<html>
  <body>
    <p>Click the button to replace "blue" with "red" in the paragraph below:</p>
    <div id="main">
      <p>Mr Blue has a blue house and a blue car.</p>
      <p>Mr Blue has a blue house and a blue car.</p>
    </div>
    <button onclick="myFunction()">Try it</button>
    <script>
      function myFunction() {
        var str = document.getElementById("main");
        var x = str.document.getElementsByTagName("p");
        var res = x.innerHTML.replace(/blue/gi, "red");
        document.getElementsByTagName("p").innerHTML = res;
      }
    </script>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript dom

0
推荐指数
1
解决办法
8727
查看次数

标签 统计

dom ×1

html ×1

javascript ×1

python ×1