Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在url更改后继续循环,并且遇到无效url错误的问题,因此我禁用了regex方法并使用了。下面是工作代码:但我仍然遇到一个大问题,PhantomJS在第一个循环中打开第一个链接后崩溃。我需要打开链接,抓取它们的内容并关闭它们(为了性能)。我在这里看到了你的_Javascript_Web Scraping_Casperjs - Fatal编程技术网

Javascript 在url更改后继续循环,并且遇到无效url错误的问题,因此我禁用了regex方法并使用了。下面是工作代码:但我仍然遇到一个大问题,PhantomJS在第一个循环中打开第一个链接后崩溃。我需要打开链接,抓取它们的内容并关闭它们(为了性能)。我在这里看到了你的

Javascript 在url更改后继续循环,并且遇到无效url错误的问题,因此我禁用了regex方法并使用了。下面是工作代码:但我仍然遇到一个大问题,PhantomJS在第一个循环中打开第一个链接后崩溃。我需要打开链接,抓取它们的内容并关闭它们(为了性能)。我在这里看到了你的,javascript,web-scraping,casperjs,Javascript,Web Scraping,Casperjs,在url更改后继续循环,并且遇到无效url错误的问题,因此我禁用了regex方法并使用了。下面是工作代码:但我仍然遇到一个大问题,PhantomJS在第一个循环中打开第一个链接后崩溃。我需要打开链接,抓取它们的内容并关闭它们(为了性能)。我在这里看到了你的答案:但这与我的问题不符。你能像我在这里显示的那样编辑你的答案吗:()所以我把它标记为接受答案?另外,如果你同意,我会发布崩溃问题和关于打开和关闭页面的优化方法的问题;并在这里提供链接。对不起,我的第一个答案有一个错误。无论您是使用waitFo


在url更改后继续循环,并且遇到无效url错误的问题,因此我禁用了regex方法并使用了。下面是工作代码:但我仍然遇到一个大问题,PhantomJS在第一个循环中打开第一个链接后崩溃。我需要打开链接,抓取它们的内容并关闭它们(为了性能)。我在这里看到了你的答案:但这与我的问题不符。你能像我在这里显示的那样编辑你的答案吗:()所以我把它标记为接受答案?另外,如果你同意,我会发布崩溃问题和关于打开和关闭页面的优化方法的问题;并在这里提供链接。对不起,我的第一个答案有一个错误。无论您是使用
waitForUrl
还是
waitForUrlChange
都没有什么区别。我不会进一步更改我的答案,但您可以发布自己的答案并接受它。感谢亲爱的Artjom,我必须将您的代码包装在一个
casper中。然后()
才能执行。另外,显然我应该将
cityName
参数添加到方法的函数中,该函数包括
casper.fills()
。否则,它将返回一个对象来填充表单。我不能使用
casper。WaitForUrl()
在url更改后继续循环,并且遇到无效url错误的问题,因此我禁用了regex方法并使用。下面是工作代码:但我仍然遇到一个大问题,PhantomJS在第一个循环中打开第一个链接后崩溃。我需要打开链接,抓取它们的内容并关闭它们(为了性能)。我在这里看到了你的答案:但这与我的问题不符。你能像我在这里显示的那样编辑你的答案吗:()所以我把它标记为接受答案?另外,如果你同意,我会发布崩溃问题和关于打开和关闭页面的优化方法的问题;并在这里提供链接。对不起,我的第一个答案有一个错误。无论您是使用
waitForUrl
还是
waitForUrlChange
都没有什么区别。我不会进一步修改我的答案,但你可以发布你自己的答案并接受它。
casper.then(function() {

    var citiesLength = cities.length;

    for (var i = 0; i < citiesLength; i++) {

        this.fill('form.wpv-filter-form',{   //setting drop-down field value to the city names in order of the items in the array
            'city[]': cityNames[i]
        });

// Apparently the code below (to the end of the loop) doesn't get executed
        casper.thenEvaluate(function() {

// Here the url change is being checked to know when the new content is loaded:
            var regexString = '(\\?)(city)(\\[\\])(=)(' + cityNames[i] + ')&';
            var regex = new RegExp(regexString, "igm");

            this.waitForUrl(regex, function(){
                var name = this.getHTML('.kw-details-title');
                link = this.evaluate(getFirstItemLink); // for test, just getting the first item's link

                casper.open(link).then(function(){
                    this.echo("New Page is loaded......");
                    // Grab the single item contents
                });
            });

        });
    }
[debug] [remote] Set "city[]" field value to city1
[info] [remote] attempting to fetch form element from selector: 'form.wpv-filter-form'
[debug] [remote] Set "city[]" field value to city2
[info] [remote] attempting to fetch form element from selector: 'form.wpv-filter-form'
[debug] [remote] Set "city[]" field value to city3
[info] [remote] attempting to fetch form element from selector: 'form.wpv-filter-form'
[info] [remote] attempting to fetch form element from selector: 'form.wpv-filter-form'
[info] [remote] attempting to fetch form element from selector: 'form.wpv-filter-form'
[info] [phantom] Step anonymous 5/5: done in 123069ms.
[info] [phantom] Step _step 6/79 https ://domain.com/section/ (HTTP 200)
[info] [phantom] Step _step 6/79: done in 123078ms.
casper.start('http://www.website.com/');

casper.then(function () {
  // Step 1
});

casper.then(function () {
  // Step 2
});

casper.then(function () {
  // Step 3
});

casper.run();
var casper = require('casper').create();

casper.start('http://casperjs.org/');

casper.then(function () {
  // "this" is "casper"
  console.log(this.getCurrentUrl()); // http://casperjs.org/
});

casper.then(function () {
  // "this" is "casper"
  this.echo(this.evaluate(function () {
    // "this" is "window"
    return this.location.href; // http://casperjs.org/
  }));
});

casper.run();
cityNames.forEach(function(cityName){
    casper.then(function(){
        this.fill('form.wpv-filter-form', {   //setting drop-down field value to the city names in order of the items in the array
            'city[]': cityName
        });
    });

    casper.then(function(){
        var regexString = '(\\?)(city)(\\[\\])(=)(' + cityName + ')&';
        var regex = new RegExp(regexString, "igm");
        this.waitForUrl(regex, function(){
            var name = this.getHTML('.kw-details-title');
            link = this.evaluate(getFirstItemLink); // for test, just getting the first item's link

            this.thenOpen(link).then(function(){
                this.echo("New Page is loaded......");
                // Grab the single item contents
            });
        });
    });
});