Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/molekilla/fren
A simplistic spider router
https://github.com/molekilla/fren
Last synced: about 1 month ago
JSON representation
A simplistic spider router
- Host: GitHub
- URL: https://github.com/molekilla/fren
- Owner: molekilla
- License: mit
- Created: 2015-04-09T00:23:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-26T20:37:40.000Z (almost 9 years ago)
- Last Synced: 2024-10-29T01:15:53.835Z (about 2 months ago)
- Language: JavaScript
- Size: 31.3 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
fren
=====spider state machine inspired by Angular UI Router, based on request and sprinkled by Q promises written in ES6. Uses menio.
### Example
```javascript
var fren = new Fren();
var ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.102 Safari/537.36';var MAIN_URL = 'http://www.idaan.gob.pa',
BILLING_URL = 'http://www.idaan.gob.pa//';fren
.step({
name: 'init',
method: 'get',
url: BILLING_URL,
options: {
headers: {
Referer: MAIN_URL,
'User-Agent': ua
},
jar: true
},
reduce: function ($state, response, body) {
var init = menio.parse(body, 'idaan');var nodes = {
form: {
nic: 123456,
op: init.op,
form_build_id: init.form_build_id,
form_id: init.form_id
}
};return $state.go('bill', {
options: nodes
});
}
})
.step({
name: 'bill',
url: BILLING_URL,
method: 'post',
options: {
headers: {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Referer": MAIN_URL + '/',
"User-Agent": ua
},
jar: true
},
reduce: function ($state, response) {
return $state.go('show_bill', {
url: response.headers.location
});
}
})
.step({
name: 'show_bill',
method: 'get',
options: {
jar: true,
headers: {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Referer": MAIN_URL + '/',
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36"
}
},
reduce: function ($state, response, body) {
try {
var bill = menio.parse(body, 'dashboardPart1');expect(bill.dateFormatISO).toBe('es-pa');
done();
} catch (e) {
throw e;
done();
}
}
})
.start();
```
### LicenseCopyright 2015 Rogelio Morrell C. MIT License