首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firebug/Javascript中止

Firebug/Javascript中止
EN

Stack Overflow用户
提问于 2013-10-23 06:29:13
回答 1查看 117关注 0票数 0

我是Javascript的新手。我正试图导航到一个页面并“刮”掉屏幕。我使用的是Firefox,Greasemonkey和Firebug。我正在尝试使用location.href,这可能是问题所在。我想导航到一个页面,解析内容,使用内容导航到其他页面。下面是一个例子(我的站点不同,但我得到了相同的错误/结果):

代码语言:javascript
复制
location.href='http://www.w3schools.com/html/html_examples.asp';
/* parse and find text */
location.href='http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro';
alert('finished');

不管我怎么做,Firebug/Greasemonkey在第一个location.href之后就退出了。警报将会显示,但即使我在那里设置了断点,它也会直接经过它。任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

发布于 2013-10-26 19:19:27

场景1:大量动态生成的链接(使用 )获取

代码语言:javascript
复制
//...
//@include http://www.w3schools.com/html/html_examples.asp
//@grant   GM_xmlhttpRequest
//...

var urls = [];
//parse text to generate some links on the fly and store them in urls[]
var i = 0, numUrls = urls.length, reportEntries = [], count = 0;
for(; i < numUrls; i++) {
    GM_xmlhttpRequest({
        method: 'GET', 
        url: urls[i], 
        onload: function(response) {
            var returnedHtml = response.responseText;
            //extract more information from returnedHtml and store it in reportEntries[i]
            if(++count >= numUrls) {
                //print reportEntries[] to form a report
                alert('finished');
            }
        }
    })
}

注意:如果您需要将报告作为文本文件保存到本地磁盘,则Greasemonkey不是一个可行的选项,因为它没有打开本地文件的权限。尽管如此,您仍然可以将其保存到在线存储,如pastebin.com。

场景2:有限数量的静态链接

代码语言:javascript
复制
//...
//@include  http://some.landing/page
//@include  http://www.w3schools.com/html/html_examples.asp
//@include  http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro
//...
if('http://some.landing/page' == location.href) {
    location.href = 'http://www.w3schools.com/html/html_examples.asp';
}
else if('http://www.w3schools.com/html/html_examples.asp' == location.href) {
    /* parse and find text */
    location.href='http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro';
}
else if('http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro' == location.href) {
    alert('finished');
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19529532

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档