Skip to content

Commit 427e7f2

Browse files
written, needs to be tested better.
1 parent 9c4e329 commit 427e7f2

File tree

16 files changed

+1133
-180
lines changed

16 files changed

+1133
-180
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
node_modules
22
npm-debug.log
3+
.DS_Store
4+
examples/_*
5+
examples/*.json

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
test:
33
@./node_modules/.bin/mocha \
44
--require should \
5-
--reporter spec
5+
--reporter spec \
6+
--timeout 20s
67

7-
.PHONY: test
8+
.PHONY: test

Readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
structure any website
55

6+
##
7+
68
## License
79

810
(The MIT License)

examples/dribbble-search.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Module Dependencies
3+
*/
4+
5+
var xray = require('..');
6+
var write = require('fs').createWriteStream(__dirname + '/dribbble-search.json');
7+
8+
/**
9+
* Base URL
10+
*/
11+
12+
var url = 'https://dribbble.com/search?q=form';
13+
14+
/**
15+
* x-ray
16+
*/
17+
18+
xray(url)
19+
.selector('.dribbbles > li')
20+
.property('url', '.dribbble-img > .dribbble-link', 'href')
21+
.property('name', '.dribbble-img img', 'alt')
22+
.property('image', '.dribbble-img img', 'src')
23+
.paginate('.next_page')
24+
// .format(format)
25+
.run(function(err, json) {
26+
if (err) throw err;
27+
// console.log(json);
28+
// console.log(json);
29+
// console.log('called');
30+
// var str = JSON.stringify(arr, true, 2);
31+
// write(__dirname + '/dribble.json', str, 'utf8');
32+
// console.log('crawled!');
33+
})
34+
.end(function(err, json) {
35+
console.log(err, json);
36+
})
37+
.stream(write);
38+
// .end(function(err) {
39+
// if (err) throw err;
40+
// console.log('crawled');
41+
// });
42+
43+
/**
44+
* Images
45+
*/
46+
47+
function images($el, $) {
48+
var imgs = [];
49+
50+
$el.find('a').each(function(i, el) {
51+
imgs.push($(el).attr('data-src'));
52+
})
53+
54+
return imgs;
55+
}
56+
57+
/**
58+
* Format
59+
*/
60+
61+
function format(json) {
62+
json.tags = json.tags.split(',');
63+
json.shots = +json.shots.replace(/\D+/g, '');
64+
json.followers = +json.followers.replace(/\D+/g, '');
65+
}

examples/github-stars.js

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,71 @@
1+
/**
2+
* Module Dependencies
3+
*/
14

2-
Structural
3-
.url('https://github.com/stars/matthewmueller?direction=asc&language=javascript&sort=created')
4-
.url('https://github.com/stars/matthewmueller?direction=desc&language=javascript&sort=created')
5-
.key('title', 'div > ul > li.repo-list-item.public.source > h3.repo-list-name > a')
5+
var xray = require('..');
6+
var array = require('array');
7+
var fmt = require('util').format;
8+
9+
/**
10+
* Urls
11+
*/
12+
13+
var languages = [
14+
'JavaScript',
15+
'CSS',
16+
'CoffeeScript',
17+
'Ruby',
18+
'Python',
19+
'Shell',
20+
'Go',
21+
'C',
22+
'C++',
23+
'Objective-C',
24+
'PHP',
25+
'VimL',
26+
'Java',
27+
'Swift',
28+
'Scala',
29+
'TeX',
30+
'Perl',
31+
'Lua',
32+
'Clojure',
33+
'IDL',
34+
'Objective-C++',
35+
'Processing',
36+
'R',
37+
'Vala',
38+
'Lisp',
39+
'XSLT',
40+
'LiveScript',
41+
'TypeScript'
42+
];
43+
44+
/**
45+
* Get the urls
46+
*/
47+
48+
var base = 'https://github.com/stars/matthewmueller?direction=%s&language=%s&sort=created';
49+
var urls = [];
50+
languages.forEach(function(language) {
51+
language = decodeURIComponent(language);
52+
urls.push(fmt(base, 'asc', language));
53+
urls.push(fmt(base, 'desc', language));
54+
})
55+
56+
/**
57+
* Use
58+
*/
59+
60+
xray(urls)
61+
.key('repo', 'div > ul > li.repo-list-item.public.source > h3.repo-list-name > a')
662
.key('url', 'div > ul > li.repo-list-item.public.source > h3.repo-list-name > a', 'href')
763
.key('author', 'ul > li.repo-list-item.public.source > h3.repo-list-name > a > span.prefix')
864
.key('description', 'div > div > ul > li > p.repo-list-description')
65+
.key('time', '.repo-list-meta time', 'datetime')
966
.paginate('div.pagination > a:last-child')
1067
.json(function(err, json) {
1168
if (err) throw err;
12-
console.log(json);
69+
json = array(json).unique('repo').toArray();
70+
console.log(JSON.stringify(json, true, 2));
1371
})

0 commit comments

Comments
 (0)