【发布时间】:2018-05-14 06:20:06
【问题描述】:
我需要从 HTML 文件中提取信息。对于它们中的大多数,我只需要匹配特定 DOM 元素的内容或属性,因此我使用 XPATH 表达式,如 //a[@class="targeturl"]/@href 和命令行工具 xidel。
在另一批文件中,我想要的信息在 script 中,并不那么容易获得:
<html>
<head><!-- ... --></head>
<body>
...
<script>
...
var o = {
"numeric": 1234,
"target": "TARGET",
"urls": "http://example.com",
// Commented pair "strings": "...",
"arrays": [
{
"more": true
}
,
{
"itgoeson": true
}
]
};
</script>
...
</body>
</html>
请注意,包含我要获取的值的对象不是有效的 JSON。但是,它似乎尊重每行一个键值对。
我可以将什么传递给xidel --xpath "???" 以获得这个TARGET?
我用 XPATH 函数尝试了不同的东西,但是如果没有管道到其他命令,我无法找到解决方案(match 告诉我是/否,replace 逐行工作......等等)。
【问题讨论】: