我需要抓取一个网页来调试和验证数据(一次性的事情)。我可以通过导入JQuery来获取我想要的数据
var jq = document.createElement('script');
jq.src = "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
并选择我的数据:
jQuery.each(jQuery('#results h3'), function(a,x){console.log(jQuery(x).text())})
不幸的是,从控制台复制粘贴到 Excel 需要我删除行号等。有没有办法将此结果打印到更适合复制粘贴的新窗口?
最佳答案
您可以收集所有条目并立即打印它们,然后就不必处理行号:
var output = $('#results h3')
.map(function(){ return $(this).text(); })
.get()
.join("\n");
console.log(output);
这是一个示例:http://jsfiddle.net/WZ8fJ/
关于javascript - Chrome 控制台 : Print to New Window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24914864/