【发布时间】:2021-11-22 06:39:24
【问题描述】:
我们有一个 html 文件,用于测试内部工具是否正确安装。
html 文件输出两个值 Connected 或 Connection failed。
下面是我们通过浏览器打开html文件时的截图。
我需要通过 PowerShell 终端输出以上值。
我尝试了 Invoke-Webrequest,但无法获得所需的值。
Invoke-WebRequest C:\websocket.html | Select content
内容
{60、33、68、79...}
Invoke-WebRequest C:\websocket.html | Select-Object -ExpandProperty rawcontent
Content-Length: 886
Content-Type: application/octet-stream
<!DOCTYPE html>
<html>
<meta charset = "utf-8" />
<title>WebSocket Test</title>
<script language = "javascript" type = "text/javascript">
var wsUri = "ws://localhost:9091/";
var output;
function init() {
output = document.getElementById("output");
testWebSocket();
}
function testWebSocket() {
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) {
onOpen(evt)
};
websocket.onclose = function(evt){
onClose(evt)
};
}
function onClose(evt) {
document.getElementById('output').innerHTML += 'CONNECTION FAILED';
}
function onOpen(evt) {
document.getElementById('output').innerHTML += 'CONNECTED';
}
window.addEventListener("load", init, false);
</script>
<h2>WebSocket Test</h2>
<div id = "output"></div>
</html>
有什么帮助吗?
编辑: (Invoke-WebRequest C:\websocket.html).Content 60, 33, 68, 79, 67, 84, 89, 80, 69, 32, 104, 116, 109, 108, 62, 10, 60, 104, 116, 109, 108, 62, 10, 32, 32, 32, 60, 109, 101, 116, 97, 32, 99, 104, 97, 114, 115, 101, 116, 32, 61, 32, 34, 117, 116, 102, 45, 56, 34, 32, 47, 62, 10, 32, 32, 32, 60, 116, 105, 116, 108, 101, 62, 87, 101, 98, 83, 111, 99, 107, 101, 116, 32, 84, 101, 115, 116, 60, 47, 116, 105, 116, 108, 101, 62, 10, 10, 32, 32, 32, 60, 115, 99, 114, 105, 112, 116, 32, 108, 97, 110, 103, 117, 97, 103, 101, 32, 61, 32, 34, 106, 97, 118, 97, 115, 99, 114, 105, 112, 116, 34, 32, 116, 121, 112, 101, 32, 61, 32, 34, 116, 101, 120, 116, 47, 106, 97, 118, 97, 115, 99, 114, 105, 112, 116, 34, 62, 10, 32, 32, 32, 32, 32, 32, 118, 97, 114, 32, 119, 115, 85, 114, 105, 32, 61, 32, 34, 119, 115, 58, 47, 47, 108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 57, 48, 57, 49, 47, 34, 59, 10, 32, 32, 32, 32, 32, 32, 118, 97, 114, 32, 111, 117, 116, 112, 117, 116, 59, 10, 9, 10, 32, 32, 32, 32, 32, 32, 102, 117, 110, 99, 116, 105, 111, 110, 32, 105, 110, 105, 116, 40, 41, 32, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 111, 117, 116, 112, 117, 116, 32, 61, 32, 100, 111, 99, 117, 109, 101, 110, 116, 46, 103, 101, 116, 69, 108, 101, 109, 101, 110, 116, 66, 121, 73, 100, 40, 34, 111, 117, 116, 112, 117, 116, 34, 41, 59, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 116, 101, 115, 116, 101, 98, 83, 111, 99, 107, 101, 116, 40, 41, 59, 10, 32, 32, 32, 32, 32, 32, 125, 10, 9, 10, 32, 32, 32, 32, 32, 32, 102, 117, 110, 99, 116, 105, 111, 110, 32, 116, 101, 115, 116, 87, 101, 98, 83, 111, 99, 107, 101, 116, 40, 41, 32, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 119, 101, 98, 115, 111, 99, 107, 101, 116, 32, 61, 32, 110, 101, 119, 32, 87, 101, 98, 83, 111, 99, 107, 101, 116, 40, 119, 115, 85, 114, 105, 41, 59, 10, 9, 9, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 119, 101, 98, 115, 111, 99, 107, 101, 116, 46, 111, 110, 111, 112, 101, 110, 32, 61, 32, 102, 117, 110, 99, 116, 105, 111, 110, 40, 101, 118, 116, 41, 32, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 111, 110, 79, 112, 101, 110, 40, 101, 118, 116, 41, 10, 32, 32, 32, 32, 32, 32, 32、32、32、125、59、10、10、9、32、119、101、98、115、111、99、107、101、116、46、111、110、99、108、111、115、 101, 32, 61, 32, 102, 117, 110, 99, 116, 105, 111, 110, 40, 101, 118, 116, 41, 123, 10, 9, 9, 111, 110, 67, 108, 111, 115, 101, 40, 101, 118, 116, 41, 10, 9, 32, 125, 59, 10, 32, 32, 32, 32, 32, 32, 125, 10, 10, 9, 102, 117, 110, 99, 116, 105, 111, 110, 32, 111, 110, 67, 108, 111, 115, 101, 40, 101, 118, 116, 41, 32, 123, 10, 9, 9, 100, 111, 99, 117, 109, 101, 110, 116, 46, 103, 101, 116, 69, 108, 101, 109, 101, 110, 116, 66, 121, 73, 100, 40, 39, 111, 117, 116, 112, 117, 116, 39, 41, 46, 105, 110, 110, 101, 114, 72, 84, 77, 76, 32, 43, 61, 32, 39, 67, 79, 78, 78, 69, 67, 84, 73, 79, 78, 32, 70, 65, 73, 76, 69, 68, 39, 59, 10, 9, 125, 10, 9, 10, 32, 32, 32, 32, 32, 32, 102, 117, 110, 99, 116, 105, 111, 110, 32, 111, 110, 79, 112, 101, 110, 40, 101, 118, 116, 41, 32, 123、10、9、100、111、99、117、109、101、110、116、46、103、101、116、69、108、101、109、101、110、116、66、121、73、 100, 40, 39, 111, 117, 116, 112, 117, 116, 39, 41, 46, 105, 110, 110, 101, 114, 72, 84, 77, 76, 32, 43, 61, 32, 39, 67, 79, 78, 78, 69, 67, 84, 69, 68, 39, 59, 10, 10, 32, 32, 32, 32, 32, 32, 125, 10, 9, 10, 32, 32, 32, 32, 32, 32, 119, 105, 110, 100, 111, 119, 46, 97, 100, 100, 69, 118, 101, 110, 116, 76, 105, 115, 116, 101, 110, 101, 114, 40, 34, 108, 111, 97, 100, 34, 44, 32, 105, 110, 105, 116, 44, 32, 102, 97, 108, 115, 101, 41, 59, 10, 32, 32, 32, 10, 32, 32, 32, 60, 47, 115, 99, 114, 105, 112, 116, 62, 10, 10, 32, 32, 32, 60, 104, 50, 62, 87, 101, 98, 83, 111, 99, 107, 101, 116, 32, 84, 101, 115, 116, 60, 47, 104, 50, 62, 10, 32, 32, 32, 60, 100, 105, 118, 32, 105, 100, 32, 61, 32, 34, 111, 117, 116, 112, 117, 116, 34, 62, 60, 47, 100, 105, 118, 62, 10, 10、60、47、104、116、109、108、62、10
【问题讨论】:
-
(Invoke-WebRequest C:\websocket.html).Content说什么? -
@Theo:它只是输出一系列随机数。
-
那些不是随机数,它们是html文本的ascii值
-
60,33,68,79,67,84,89,80,69,32,104,116,109,108,62拼写<!DOCTYPE html> -
为了处理 javascript,请尝试检查
Invoke-WebRequest返回的ParsedHtml属性,而不是 content/rawcontent。
标签: html windows powershell