[英]How to use urls saved in a data base as source for source urls in casperjs using php?
I have a small problem, i am new to casperjs so i was wondering if casper can work hand in hand with my current php script that loops through the results of of my database query results. 我有一个小问题,我是casperjs的新手,所以我想知道casper是否可以与当前遍历数据库查询结果的php脚本一起工作。
<?php
$urls = query url database
foreach($url as $url){
then I send an execute command to casperjs.
}
?>
Then here is the js code where i want looped urls to be sent. 然后这是我要发送循环网址的js代码。
var casper = require('casper').create({
viewportSize: {
width: 1024,
height: 768
}
});
casper.start(**URL from PHP HERE**, function() {
this.capture('shy.png', {
top: 0,
left: 0,
width: 1024,
height: 1000
});
});
casper.run();
my question is how do i send the command with a $url as the url source value to casperjs? 我的问题是如何将带有$ url作为url源值的命令发送给casperjs?
I am trying to make screenshot for each url supplied. 我正在尝试为提供的每个网址制作屏幕截图。
You can pass the URL to casperjs process via shell commands: 您可以通过外壳命令将URL传递给casperjs进程:
CasperJS CLI commands CasperJS CLI命令
eg casperjs --crawlurl= http://example.com 例如casperjs --crawlurl = http://example.com
Then, you can call the casperjs process from PHP with something like shell_exec: 然后,您可以使用shell_exec之类的东西从PHP调用casperjs进程:
Note that for normal server provider, they may block the use of shell_exec. 请注意,对于普通服务器提供程序,它们可能会阻止使用shell_exec。
You could just echo the urls in tags with the php script. 您可以使用php脚本回显标签中的网址。
<?php
$urls = do_query();
foreach($urls as $url){
echo "<a href=\"$url\"">$url</a><br />;
}
?>
Inject jQuery with your casperjs. 用casperjs注入jQuery。 Then use casperjs evaluate() with a jQuery selector on all the links to return all the links again. 然后在所有链接上使用带有jQuery选择器的casperjsvaluate()再次返回所有链接。
var links = this.evaluate( function() {
var $ = jQuery; // map jQuery to $
var links = [];
$('a').each( function() {
links.concat($(this).attr('href'));
});
return links;
});
Then loop through the links and capture them. 然后循环浏览链接并捕获它们。
Good luck! 祝好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.