javascript - 如何从网站 javascript 中获取价值?
问题描述
在网页上我有这个:
<table class="infobox"><tr>
<td>
<table class="infobox-inner-table">
<tr class="infobox-heading">
<th id="infobox-quick-facts">Quick Facts</th>
</tr>
<tr><td>
<div class="infobox-spacer"></div>
<div id="infobox-contents-0"></div>
<script>
WH.markup.printHtml("[ul][li]Requires level 20[\/li][li]Loremaster: Yes[\/li][li]Side: [span class=icon-alliance]Alliance[\/span][\/li][li][icon name=quest_start]Start: [url=\/npc=41129\/surveyor-thurdan]Surveyor Thurdan[\/url][\/icon][\/li][li][icon name=quest_end]End: [url=\/npc=41129\/surveyor-thurdan]Surveyor Thurdan[\/url][\/icon][\/li][li]Sharable[\/li][li]Added in patch 4.0.3.13277[\/li][\/ul]", "infobox-contents-0", {
allow: WH.markup.CLASS.STAFF,
dbPage: true, });
</script>
</td></tr>
</table>
javascript里面是“在补丁4.0.3.13277中添加”,通过VBA我必须得到补丁号。
最好是使用 getelementsbyclassname("infobox") 所以它只会看这个,但是我不知道下一步该做什么, .innerText 或任何类似的挖掘补丁号的东西在这里不适用。
解决方案
您可以正则表达式输出适当的脚本内容,然后替换\/
为/
; 替换[
为<
; 替换]
为 >
; 然后用 html 解析器解析并抓取最后一个li
元素。
Option Explicit
Public Sub GetTextFromScriptTag()
'required references Microsoft HTML Object Library; Microsoft VBScript Regular Expressions
'your code
Dim html As MSHTML.HTMLDocument, re As VBScript_RegExp_55.RegExp
'Set html = htmlsourceobject(e.g.ie.document) ''< this line you need to add in html source object from your prior code
Set re = New VBScript_RegExp_55.RegExp
re.Pattern = "WH\.markup\.printHtml\(""(.*?)"","
html.body.innerHTML = "<body>" & Replace$(Replace$(Replace$(re.Execute(html.body.innerHTML)(0).SubMatches(0), "[", "<"), "]", ">"), "\/", "/") & "<\body>"
Dim liNodes As Object
Set liNodes = html.querySelectorAll("li")
Debug.Print liNodes.item(liNodes.Length - 1).innerText
End Sub
正则表达式:
推荐阅读
- java - 获取Java中所有出现的二元组
- python-3.x - 下个月记录 Pandas 中的搜索值
- sql - 如何在大表上执行自连接
- java - E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 error after copy file to other PC
- r - 如何按 customer_name 分组并计算 mail_sent?
- python - 我的火车测试数据拆分不起作用。unigrams 为所有类别显示相同的单词
- java - 禁止自定义 FreeMarker 指令的所有空格和新行
- postgresql - 如何接当前分类的二级分类
- java - Session.flush() 导致 org.hibernate.StaleStateException:批量更新从更新返回了意外的行数:1 实际行数:0 预期:1
- php - Js Validator Plugin远程规则用于在Ajax调用后不刷新页面不工作的唯一值检查