Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamicScraper can not run #73

Open
willin opened this issue Jul 18, 2017 · 5 comments
Open

DynamicScraper can not run #73

willin opened this issue Jul 18, 2017 · 5 comments

Comments

@willin
Copy link

willin commented Jul 18, 2017

yarn global add phantomjs-prebuilt
// ./doc/examples/HackerNews.js
var sjs = require('../../src/Scraper');
/*
 Scrape the news in Hacker News.
 */
sjs.DynamicScraper
	.create('https://news.ycombinator.com')
	.scrape(function ($) {
		return $('.title a').map(function () {
			console.log($(this).text());
			return $(this).text();
		}).get().filter(function (elm) {
			return elm != 'More';
		});
	})
	.then(function (news) {
		news.forEach(function (elm) {
			console.log(elm);
		});
	}).catch(function (err) { 
		console.error(err);
	});

run and did not get any result...

@ezuid
Copy link

ezuid commented Jul 27, 2017

+1

@bryanrasmussen
Copy link

same here, my code

var scraperjs = require('scraperjs');
scraperjs.DynamicScraper.create('http://www.sundhed.dk')
.scrape(function($) {
console.log('scrape worked');
return $("a").map(function() {
console.log('map');
return $(this).attr('href');
}).get();
})
.then(function(links) {
console.log(links).
})

the page is running angular so it needs to be interpreted to extract the urls in this case.
I was thinking that maybe the dynamic scraper was running too soon and needed to wait to make sure it had the urls to get, but I guess the hacker news example doesn't actually need a dynamic scraper and all the urls should be available on load?

The html that loads before the script evaluates has a few urls inside of a conditional comment, when I use the static scraper on the site I get those urls out.

@willin
Copy link
Author

willin commented Aug 5, 2017

phantom@0.8.4: v1 is no longer maintained, please upgrade to v2.0+ as soon possible.

@hotnAny
Copy link

hotnAny commented Oct 10, 2017

ran the sample code and didn't get any result ...

var scraperjs = require('scraperjs'); scraperjs.DynamicScraper.create('https://news.ycombinator.com/') .scrape(function($) { return $(".title a").map(function() { return $(this).text(); }).get(); }) .then(function(news) { console.log(news); })

@MatthewKosloski
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants