javascript - 如何在 Python 中从 Javascript 中获取变量
问题描述
我正在尝试制作一个从 javascript 文件中读取 JSON 字符串的程序,但我似乎做不到。我只能和我想要的相反。这是我的代码
#python 2.7?
import sys
from subprocess import Popen, PIPE
messages = [] #store messages from send.js
sensor = Popen([communication.html, send.js])
buffer = b''
while True:
# read the sensor a character at a time
out = sensor.stdout.read(1)
#after reading
if out = b'\n':
messages.append(float(buffer))
print(messages)
buffer = b''
else:
buffer += out #append to buffer
//javascript
function sendMsg(){
var msg = document.getElementById('talk').value;
var data = {
"sending": msg
};
data = JSON.stringify(data)
}
<!DOCTYPE html>
<html>
<head>
<!--<script src="comScrp.py"></script>-->
</head>
<body>
<script src="send.js"></script>
<!--Without the Python, we wouldn't be able to use this without a server or nodeJs.-->
<input id="talk"><button onclick="sendMsg()">Send</button>
<p id="output"></p>
</body>
</html>
谢谢!
解决方案
推荐阅读
- python - Raspberry Pi 上的 Python 脚本会随着时间的推移而变慢
- java - 如何在工件 GCP 存储中上传文件夹
- swift - 如何在 SubView SwiftUI 中使用 BaseView @State 属性
- firebase - 在本机反应中找不到 Firebase crashlytics 崩溃日志?
- asp.net - 是否有跨平台的替代代码
- c# - 在 EF 中获取最后一个可能的 Id 是更快/更好的选择:MaxAsync 与 LastAsync?
- php - 警告:number_format() 期望参数 1 为浮点数,字符串在 D:\xampp\htdocs\website\foodpoint\welcome.php 第 205 行给出
- android - 在没有服务的情况下继续在后台运行 CountdownTimer
- python - 熊猫计算给出不正确的小数点
- javascript - 在 Materializecss Carousel 中更改子项目的 translatex 和 translatey