scraperjs icon indicating copy to clipboard operation
scraperjs copied to clipboard

Scraper function will not work unless it matches regex pattern

Open Alanz2223 opened this issue 8 years ago • 0 comments

I spent a few hours tracking this one down. I encountered a 'cannot read property error of undefined' when I supplied a scrape function into the .scrape promise. I followed everything step by step and wrote the code myself so that I can memorize the flow. It didn't work. Then I pasted the exact same procedure from the examples folder and sure enough the thing ran without a problem. What happened was that the function you supply is turned into a string and then manipulated to extract the whatever is inside the block. This is done through a regex to match the enclosing 'function(){..}' stuff but the regex doesn't work unless there is a space between the closing parentheses and the starting bracket.

so this

.scrape( function($) { .. .... } )

will work just fine, but this

.scrape( function($){ .. .... } )

throws the null error.

a very subtle difference but it can give you headaches.... Anyways I hope someone who is better with regex expressions can fix this.

the current exp is

var rg = /^function\s+([a-zA-Z_$][a-zA-Z_$0-9])?((.?)) {/g;

within the PhantomWrapper.js file

Alanz2223 avatar May 27 '16 17:05 Alanz2223