ruipgil / scraperjs

A complete and versatile web scraper.
MIT License
3.7k stars 188 forks source link

Pass parameter to scrape evaluate function #72

Closed art1c0 closed 7 years ago

art1c0 commented 7 years ago

I need to make query selector parameterized for evaluate function. For example, in this code:

    .scrape(function($) {
        return $(".title a").map(function() {
            return $(this).text();
        }).get();
    })

I need this ".title a" to be dynamic, coming as parameter. How to achieve that? This is very crusial... Thanks!

art1c0 commented 7 years ago

For those who might wonderm the soution is:

    .scrape(
        function($, query) {
            return $(query).map(function() {
                return $(this).text();
            }).get();
        },
        function(data, utils) {
            console.log('data', data);
        },
        queryString
    );