Skip to content

Commit

Permalink
添加 Node.js 爬虫 Sample。
Browse files Browse the repository at this point in the history
  • Loading branch information
imlinhanchao committed Apr 3, 2018
1 parent d3ed66d commit 1faa2c8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
*.obj
*.out
*.pyc
package-lock.json
.vscode
8 changes: 6 additions & 2 deletions 01/crawler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
from urllib2 import urlopen # Python 2


rsp = urlopen('http://ip.sxisa.com/')
print(rsp.read())
def ip():
rsp = urlopen('http://ip.sxisa.com/')
return rsp.read()

if __name__ == '__main__':
print(ip())
15 changes: 15 additions & 0 deletions 01/crawler/node/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node
const request = require('request');

function ip(callback) {
request('http://ip.sxisa.com/', (err, rsp, body) => {
if (err) throw (err)
if (callback) callback(body)
})
}

module.exports = ip;

if (require.main === module) {
ip(console.log);
}
14 changes: 14 additions & 0 deletions 01/crawler/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "crawler",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"start": "node ./app.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"request": "^2.85.0"
}
}

0 comments on commit 1faa2c8

Please sign in to comment.