Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added support for <head>

  • Loading branch information...
commit 3058ba791d89252a7ba9649550f5c6621b292dfb 1 parent bbf0111
Mathias Pettersson mape authored

Showing 3 changed files with 4 additions and 3 deletions. Show diff stats Hide diff stats

  1. +2 2 examples/test.js
  2. +1 0  lib/scraper.js
  3. +1 1  package.json
4 examples/test.js
@@ -8,7 +8,7 @@ http.createServer(function (request, response) {
8 8 links += '<a href="/">Test - '+i+'</a>';
9 9 };
10 10 response.writeHead(200, {'Content-Type': 'text/plain'});
11   - response.end('<html><body><div id="time">'+respondTime+'</div>'+links+'</body></html>\n');
  11 + response.end('<html><head><title>Page has '+linkCount+' links</title></head><body><div id="time">'+respondTime+'</div>'+links+'</body></html>\n');
12 12 }, respondTime);
13 13 }).listen(8486);
14 14
@@ -26,7 +26,7 @@ setTimeout(function() {
26 26 console.log(err);
27 27 return;
28 28 }
29   - console.log('Server took '+$('#time').text()+'ms to respond, found '+$('a').length+' <a> @ '+new Date().toString());
  29 + console.log('Server took '+$('#time').text()+'ms to respond, found '+$('a').length+' <a> @ '+new Date().toString()+' with title "'+$('title').text()+'"');
30 30 }, {
31 31 'reqPerSec': 0.5
32 32 });
1  lib/scraper.js
@@ -54,6 +54,7 @@ module.exports = function scrape(requestOptions, callback, fetchOptions) {
54 54 if (response && response.statusCode == 200) {
55 55 var window = jsdom.jsdom().createWindow();
56 56 jsdom.jQueryify(window, function(win, $) {
  57 + $('head').append($(body).find('head').html());
57 58 $('body').append($(body).find('body').html());
58 59 callback(null, $, requestOptions['uri']);
59 60 });
2  package.json
... ... @@ -1,7 +1,7 @@
1 1 {
2 2 "name" : "scraper",
3 3 "description" : "Easier web scraping using jQuery.",
4   - "version" : "0.0.6",
  4 + "version" : "0.0.7",
5 5 "author" : "Mathias Pettersson <mape@mape.me>",
6 6 "engines" : ["node"],
7 7 "directories" : { "lib" : "./lib" },

0 comments on commit 3058ba7

Please sign in to comment.
Something went wrong with that request. Please try again.