This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var iframe = document.getElementsByName('f3')[0]; //获取显示帖子内容的 iframe | |
//初始化抓取结果,它是一个 HTML 页面,因此先把头部以及简单的几个样式放进去 | |
var page = '<!DOCTYPE html><html><head><title>SMTH</title><style>div {border-top: 1px solid yellowgreen; padding: 10px; color: royalblue;}</style></head><body>'; | |
//点击打开第一个帖子就可以激活下面的函数执行 | |
iframe.onload = function(){ | |
var innerDoc = iframe.contentDocument || iframe.contentWindow.document; //获取 iframe 里的 document 对象 | |
var post = innerDoc.getElementsByClassName('article')[0].innerHTML; //获取帖子内容对应的 HTML 元素 | |
page += '<div>'+post.replace(/src="/g, 'src="http://www.2.newsmth.net/')+'</div>'; //把当前的帖子内容加入抓取结果的 HTML 页面里 | |
var next = innerDoc.getElementsByClassName('conPager smaller right')[0].children[1].href; //获取下一个帖子的链接地址 | |
if(iframe.src != next) { //判断是否抓取完成 |