我正在开发一个基于web的应用程序,它使用对http://www.whateverorigin.org/的调用加载URL的HTML内容,这避免了同一源策略冲突
url = 'http://' + document.getElementById("urlText").value
$.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent(url) + '&callback=?', function(data){
var doc = new DOMParser().parseFromString(data.contents, 'text/html');
如果我需要从这个html字符串中提取有意义的可见文本,有没有一种方法可以像beautifulsoup在python中那样做呢?我更像是javascript的初学者。你知道吗
看起来这就是你需要的?下面的代码分析谷歌.nl与whateverorigin.org网站网站,并将其添加到一个div。如果没有,请尝试解释你还需要什么!你知道吗
jQuery:
$(document).ready(function() { $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent('http://www.google.nl') + '&callback=?', function(data){ $('.result').html(data.contents); }); });
HTML:
例如:http://jsfiddle.net/qddekhnc/1/
使用jQuery查找并iterate覆盖适当的元素。然后您可以决定打印出什么-例如:显示可见项的文本节点。 下面是一个jsfiddle和一个工作脚本示例:http://jsfiddle.net/w147o9f6/1/
javascript代码:
相关问题 更多 >
编程相关推荐