Created
February 4, 2014 23:21
-
-
Save avevlad/8814465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
debugger; | |
request = require('request') | |
cheerio = require('cheerio') | |
async = require('async') | |
fs = require('fs') | |
url = [] | |
item = 37 | |
headers = { | |
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0', | |
'Content-Type': 'application/x-www-form-urlencoded' | |
} | |
req = (url) -> | |
request.get | |
url: url | |
headers: headers | |
, (error, response, body) -> | |
console.log "Парсим юзера # #{item} -- #{url}" | |
console.log body | |
console.log response.statusCode | |
if (!error && response.statusCode == 200) | |
prs(body) | |
prs = (body) -> | |
body = JSON.parse(body) | |
link = body.blog | |
if link == "" | |
item++; | |
setTimeout( -> | |
req(url[item]) | |
, 3000) | |
else | |
link = link + '\n' | |
appendFile(link) | |
appendFile = (text) -> | |
file = './result/site.txt' | |
fs.appendFile file, text, (err) -> | |
throw err if err | |
console.log "Файл записан!" | |
item++; | |
setTimeout( -> | |
req(url[item]) | |
, 3000) | |
getUser = () -> | |
file = './result/user.txt' | |
data = fs.readFileSync(file) | |
url = data.toString().split("\n") | |
req(url[item]) | |
getUser(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment