2013-07-04 10 views
6

Ubuntu 12.04 üzerinde Node v0.10.11 kullanıyorum. İstek URL'si ile çalışan bir URL akışı yapmak için neyi kaçırdığımı anlayamıyorum. Bu program, bir posta listesi sitesine gitmeye, her ay için indirme linklerini bulmaya ve her ay için sayfaları indirmeye çalışıyor.Düğüm isteği atıyor: Hata: Geçersiz URI "www.urlworksinbrowser.com" veya options.uri gerekli bir argüman

mikeal's readme, "İlk argüman bir url veya bir options nesnesi olabilir. Tek gerekli seçenek, uri, diğerlerinin tümü isteğe bağlıdır. uri || url - url'den tamamen kalifiye bir uri veya ayrıştırılmış bir url nesnesi. parse() "

Eğer url.parse (www.targeturl.com) adını alırsam, [Error: options.uri gerekli bir argüman] alırım Eğer url.parse'yi kullanmazsam, : Geçersiz URI "www.freelists.org/archive/si-list/06-2013"] (bu bağlantı benim tarayıcılarımda gayet iyi çalışıyor)

Kodu 42 satıra indirdim. Herhangi bir tavsiye

var request = require('request'), 
    url = require('url'), 
    stream = require('stream'), 
    cheerio = require('cheerio'), // a reduced jQuery style DOM library 
    Transform = require('stream').Transform 

var DomStripStream = function(target) { 
    this.target = target; 
    stream.Transform.call(this,{objectMode: true}); 
} 
DomStripStream.prototype = Object.create(
    Transform.prototype, {constructor: {value: DomStripStream}} 
) 
DomStripStream.prototype.write = function() { 
    this._transform.apply(this, arguments); 
}; 
DomStripStream.prototype.end = function() { 
    this._transform.apply(this, arguments); 
    this.emit("end"); 
}; 

DomStripStream.prototype._transform = function(chunk, encoding, callback) { 
    chunk = chunk ? chunk.toString() : ""; 
    $ = cheerio.load(chunk); 
    domLinks = $(this.target); 
    $(domLinks).each(function (i, link) { 
    currLink = 'www.freelists.org' + $(link).attr('href') 
// currLink = url.parse(currLink) 
    request(currLink, function (error, response, body) { 
     console.log(error); 
    }) 
    }); 
} 

var fs = require("fs"), 
    output = fs.createWriteStream("out.txt"), 
    mainPage = new DomStripStream('td a') 

request('http://www.freelists.org/archive/si-list'). 
pipe(mainPage). 
pipe(output); 
+1

url http verin: // veya https: url – user568109

cevap

13

eklenti http hoşgeldin: // veya https: //

+2

ummm, nasıl kök gösterirler // URL? Yolu biliyorum, ama eğer geliştirme veya üretimde olduğumda kök farklıdır ... bu yüzden http: // {root} /path............. sadece http: // yolunu geçemem .. .. –

+0

'document.location' kontrol edin,' protokol' alanını içerir. [MDN] (https://developer.mozilla.org/en-US/docs/Web/API/Document/location) – Laoujin

İlgili konular