Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most elegant way to do screen scraping in node.js?

I'm in the process of hacking together a web app which uses extensive screen scraping in node.js. I feel like I'm fighting against the current at every corner. There must be an easier way to do this. Most notably, two things are irritating:

  1. Cookie propagation. I can pull the 'set-cookie' array out of the response headers, but performing string operations to parse the cookies out of the array feels extremely hackish.

  2. Redirect following. I want each request to follow through redirects when a 302 status code is returned.

I came across two things which looked useful, but I couldn't use in the end:

  • http://zombie.labnotes.org/, but it doesn't have HTTPS support, so I can't use it.

  • http://www.phantomjs.org/, but couldn't use it because it doesn't (appear to) integrate with node.js. It's also pretty heavyweight for what I'm doing.

Are there any JavaScript screenscraping-esque libraries which propagate cookies, follow redirects, and support HTTPS? Any pointers on how to make this easier?

like image 970
Mike Avatar asked Mar 26 '11 08:03

Mike


People also ask

Is NodeJS good for web scraping?

Web scraping is the process of extracting data from a website in an automated way and Node. js can be used for web scraping. Even though other languages and frameworks are more popular for web scraping, Node. js can be utilized well to do the job too.

Which web scraping is best?

1. Scrape.do. Scrape.dois an easy-to-use web scraper tool, providing a scalable, fast, proxy web scraper API in an endpoint. Based on cost-effectiveness and features, Scrape.do is on top of the list.

What is the difference between screen scraping and data scraping?

Difference between screen scraping and data scrapingData scraping is a variant of screen scraping that is used to copy data from documents and web applications. Data scraping is a technique where structured, human-readable data is extracted.


2 Answers

i actually have a scraper library now https://github.com/mikeal/spider it's quite nice, you can use jquery and routes.

feedback is welcome :)

like image 85
mikeal Avatar answered Sep 19 '22 04:09

mikeal


You may want to check out https://github.com/mikeal/request from mikeal, I just spoke to him the chatroom and he says that it does not handle cookies at the moment but you can write a submodule to handle these for you in the meantime.

in regards to redirect it handles beautifully :)

like image 45
RobertPitt Avatar answered Sep 18 '22 04:09

RobertPitt