html =
( %
<html>
<body>
<table style="width: 100%">
    <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Age</th>
    </tr>
    <tr>
        <td>Jill</td>
        <td>Smith</td>
        <td>50</td>
    </tr>
    <tr>
        <td>Eve</td>
        <td>Jackson</td>
        <td>94</td>
    </tr>
</table>
</body>
</html>
)

; https://www.autohotkey.com/boards/viewtopic.php?t=95337

Doc := ComObjCreate("htmlfile")
Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=edge"">")
Doc.write(html)
script =
( %
   var collHeaders = document.querySelectorAll("th");
   var collData = document.querySelectorAll("td");
   var arr = [], obj = {}, idx = 0;
   for (var i = 0; i < collData.length; i++) {
      idx = i % collHeaders.length;
      obj[collHeaders[idx].innerText] = collData[i].innerText;
      if (idx == collHeaders.length - 1)
         arr.push(obj), obj = {};
   }
   JSON.stringify(arr, "", "  ")
)
MsgBox, % Doc.parentWindow.eval(script)

 

声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。