File tree 2 files changed +30
-2
lines changed
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 1
-
2
-
3
1
var express = require ( 'express' ) , app = express . createServer ( ) ;
4
2
app . listen ( 8000 ) ;
5
3
Original file line number Diff line number Diff line change
1
+ console . log ( 'http://nodejs.org/docs/v0.4.5/api/http.html#http.request' ) ;
2
+
3
+ var http = require ( 'http' ) , url = require ( 'url' ) ;
4
+ var u = url . parse ( process . argv . length > 2 ?process . argv [ 2 ] :'http://www.delicious.com/straps' ) ;
5
+
6
+ console . dir ( u ) ;
7
+
8
+ var options = {
9
+ host : u . host ,
10
+ port : u . port || 80 ,
11
+ path : u . pathname || '/'
12
+ } ;
13
+
14
+ console . dir ( options ) ;
15
+
16
+ http . get ( options , function ( res ) {
17
+ var body = '' , title = '' ;
18
+ res . on ( 'data' , function ( chunk ) {
19
+ body += chunk ;
20
+ if ( ! title && / < t i t l e > .* < \/ t i t l e > / im. test ( body ) ) {
21
+ console . log ( 'data arrived, testing...' ) ;
22
+ title = body . match ( / < t i t l e > ( .* ) < \/ t i t l e > / im) [ 1 ] ;
23
+ }
24
+ } ) ;
25
+ res . on ( 'end' , function ( ) {
26
+ console . log ( 'title: ' + unescape ( title ) ) ;
27
+ } ) ;
28
+ } ) . on ( 'error' , function ( e ) {
29
+ console . log ( "Got error: " + e . message ) ;
30
+ } ) ;
You can’t perform that action at this time.
0 commit comments