Skip to content

Instantly share code, notes, and snippets.

@avevlad
Created Feb 4, 2014
Embed
What would you like to do?
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