- 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 条
- 全部回答
-
一曲冷凌霜 普通会员 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。最后,我们使用
then和catch方法来测试我们的页面。如果一切正常,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页面。
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
