账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    casperjs 的问题 about .blank的问题
    24
    0

    phantom.outputEncoding="utf-8";
    var casper=require('casper').create({请输入代码

    clientScripts:[
        //ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js
    
    ],
    pageSettings:{
        loadImages:true,
        loadPlugins:false,
        userAgent:'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'
    },
    logLevel:"debug",
    verbose:true
    

    });

    var fetcurl="https://www.tripadvisor.cn/Attraction_Review-g303783-d1238293-Reviews-Old_Town_of_Lijiang_China-Lijiang_Yunnan.html";
    casper.start(fetcurl,function(){
     {
        var name = $(this.getpagecontent()).find("#HEADING.heading_title.text");//中国丽江古城Old Town of Lijiang - China
        
         this.echo(name);
    
     }

    });
    casper.run(function() {

    this.echo("this is done ").exit()
    });
    
    

    casperjs crawl.js
    [info] [phantom] Starting...
    [info] [phantom] Running suite: 2 steps
    [debug] [phantom] opening url: https://www.tripadvisor.cn/At... HTTP GET
    [debug] [phantom] Navigation requested: url=https://www.tripadvisor.cn/At... type=Other, willNavigate=true, isMainFrame=true
    [debug] [phantom] url changed to "https://www.tripadvisor.cn/Attraction_Review-g303783-d1238293-Reviews-Old_Town_of_Lijiang_China-Lijiang_Yunnan.html"
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=about:srcdoc, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=https://tags.bluekai.com/site... type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=https://stags.bluekai.com/sit... type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Successfully injected Casper client-side utilities
    [info] [phantom] Step anonymous 2/2 https://www.tripadvisor.cn/At... (HTTP 200)
    [info] [phantom] Done 2 steps in 90654ms
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
    [debug] [phantom] url changed to "about:blank"
    [stephen@localhost crawl]$ casperjs --ignore-ssl-errors=yes --ssl-protocol=any crawl.js
    [info] [phantom] Starting...
    [info] [phantom] Running suite: 2 steps
    [debug] [phantom] opening url: https://www.tripadvisor.cn/At... HTTP GET
    [debug] [phantom] Navigation requested: url=https://www.tripadvisor.cn/At... type=Other, willNavigate=true, isMainFrame=true
    [debug] [phantom] url changed to "https://www.tripadvisor.cn/Attraction_Review-g303783-d1238293-Reviews-Old_Town_of_Lijiang_China-Lijiang_Yunnan.html"
    [debug] [phantom] Successfully injected Casper client-side utilities
    [info] [phantom] Step anonymous 2/2 https://www.tripadvisor.cn/At... (HTTP 200)
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
    [debug] [phantom] url changed to "about:blank"
    [stephen@localhost crawl]$ casperjs --ignore-ssl-errors=yes --ssl-protocol=any crawl.js
    [info] [phantom] Starting...
    [info] [phantom] Running suite: 2 steps
    [debug] [phantom] opening url: https://www.tripadvisor.cn/At... HTTP GET
    [debug] [phantom] Navigation requested: url=https://www.tripadvisor.cn/At... type=Other, willNavigate=true, isMainFrame=true
    [debug] [phantom] url changed to "https://www.tripadvisor.cn/Attraction_Review-g303783-d1238293-Reviews-Old_Town_of_Lijiang_China-Lijiang_Yunnan.html"
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=about:srcdoc, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=https://tags.bluekai.com/site... type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=https://stags.bluekai.com/sit... type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Successfully injected Casper client-side utilities
    [info] [phantom] Step anonymous 2/2 https://www.tripadvisor.cn/At... (HTTP 200)
    [info] [phantom] Done 2 steps in 9390ms
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
    [debug] [phantom] url changed to "about:blank"
    [stephen@localhost crawl]$ casperjs --ignore-ssl-errors=yes crawl.js
    [stephen@localhost crawl]$ casperjs --ignore-ssl-errors=yes --ssl-protocol=any crawl.js
    this is done
    [stephen@localhost crawl]$ casperjs --ignore-ssl-errors=yes --ssl-protocol=any crawl.js
    [info] [phantom] Starting...
    [info] [phantom] Running suite: 2 steps
    [debug] [phantom] opening url: https://www.tripadvisor.cn/At... HTTP GET
    [debug] [phantom] Navigation requested: url=https://www.tripadvisor.cn/At... type=Other, willNavigate=true, isMainFrame=true
    [debug] [phantom] url changed to "https://www.tripadvisor.cn/Attraction_Review-g303783-d1238293-Reviews-Old_Town_of_Lijiang_China-Lijiang_Yunnan.html"
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=about:srcdoc, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=https://tags.bluekai.com/site... type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Navigation requested: url=https://stags.bluekai.com/sit... type=Other, willNavigate=true, isMainFrame=false
    [debug] [phantom] Successfully injected Casper client-side utilities
    [info] [phantom] Step anonymous 2/2 https://www.tripadvisor.cn/At... (HTTP 200)
    [info] [phantom] Done 2 steps in 68324ms
    this is done
    [debug] [phantom] Navigation requested: url=about:blank, type=Other, willNavigate=true, isMainFrame=true
    [debug] [phantom] url changed to "about:blank"

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 一曲冷凌霜 普通会员 1楼

      在CasperJS中,我们可以通过创建一个新的HTML元素(.blank)来创建一个空的HTML页面。这是一个简单的例子:

      javascript casper.start({ page: 'http://example.com', variables: { title: 'My first page', description: 'This is my first page' } }) .then(function() { // test }) .then(function() { this.exit(); }) .catch(function() { // error });

      在这个例子中,我们首先使用casper.start方法来启动一个新的浏览器窗口。然后,我们使用page选项来指定我们想要打开的页面。在这个例子中,我们打开的是http://example.com页面。

      然后,我们使用variables选项来设置页面的标题和描述。在这个例子中,我们设置的标题是My first page,描述是This is my first page

      最后,我们使用thencatch方法来测试我们的页面。如果一切正常,then方法会返回,我们就可以退出浏览器窗口。如果发生错误,catch方法会捕获错误,并返回错误信息。

      如果你的页面是一个包含HTML元素的页面,你可以直接在页面上创建一个新的HTML元素来代替空的HTML页面。例如:

      javascript casper.start({ page: 'http://example.com', variables: { title: 'My first page', description: 'This is my first page' } }) .then(function() { // test }) .then(function() { this.exit(); }) .catch(function() { // error });

      在这个例子中,我们创建了一个新的<div>元素来代替我们的空的HTML页面。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部