在DOM中查找和提取文本

Find and Extract Text in DOM

本文关键字:提取 取文本 查找 DOM      更新时间:2023-09-26

我想从DOM中提取一段文本。我感兴趣的数据是"1234567"

<script type="text/javascript">
function example() {     
           launchChat("ABC", "1234567", "Sample Data", "Customer");      
 }
</script>

到目前为止,这就是我的

$("head").find("script").each(function(i) {
    var scr = $(this).html();   
    var regExp = /launchChat(([^)]+))/; //Outputs everything in between the brackets
    var matches = scr.match(regex);
    console.log("match " +matches);     
});

非常感谢您的帮助。

好吧,如果它在未来的某个时候对任何人都有帮助,答案是-

$("head").find("script").each(function(i) {
    var scr = $(this).html();
    if(scr.indexOf("launchChat") > 0){  
    var newTxt = scr.split('"');
    for (var i = 1; i < newTxt.length; i++) {
    console.log(newTxt[i].split('"')[3]);
    }   
}
});