以前,谷歌语音允许你使用“div”提取短信代码最近,他们使用AngularJS切换到基于ARIA的框架。如何从网页中提取包含我所有短信代码的字符串?
这是我一直在使用的目标xpath命令:
var search2 = document.evaluate('//*[@id="messaging-view"]/div/md-content/div/gv-conversation-list/md-virtual-repeat-container/div/div[2]/div[1]/div/gv-text-conversation-item/gv-conversation-item/div/div[2]/ng-transclude/gv-conversation-item-detail/gv-annotation/text()',
document, null, XPathResult.ANY_TYPE, null);
答案 0 :(得分:0)
看看Mozilla documentation on XPath in javascript。你得到的东西叫做节点迭代器。如果您像指定ANY_TYPE
那样,这可能是XPath查询最常见的返回类型。要使代码按原样运行,您可以执行以下操作:
// im putting your query in a variable for readability
var query = '//*[@id="messaging-view"]/div/md-content/div/gv-conversation-list/md-virtual-repeat-container/div/div[2]/div[1]/div/gv-text-conversation-item/gv-conversation-item/div/div[2]/ng-transclude/gv-conversation-item-detail/gv-annotation/text()';
var search2 = document.evaluate(query, document, null, XPathResult.ANY_TYPE, null);
var thisNode = iterator.iterateNext();
while (thisNode) {
console.log(thisNode.textContent); // probably will be a text node
thisNode = iterator.iterateNext();
}
或者,您可以将结果类型指定为STRING_TYPE
。
// im putting your query in a variable for readability
var query = '//*[@id="messaging-view"]/div/md-content/div/gv-conversation-list/md-virtual-repeat-container/div/div[2]/div[1]/div/gv-text-conversation-item/gv-conversation-item/div/div[2]/ng-transclude/gv-conversation-item-detail/gv-annotation/text()';
var search2 = document.evaluate(query, document, null, XPathResult.STRING_TYPE, null);
console.log(search2.stringValue);