diff --git a/new-racket-web/index.html b/new-racket-web/index.html index 659b6df99b..4291e31646 100644 --- a/new-racket-web/index.html +++ b/new-racket-web/index.html @@ -55,6 +55,7 @@ .navbar { background: rgb(245,245,245) } pre { color: black } p {color: black} + code { font-family: 'Inconsolata'} .codecomment { @@ -171,28 +172,28 @@ documentation, so click on them for more information. -
-#lang racket ; An echo server -(define listener (tcp-listen 12345)) -(let echo-server () - (define-values (in out) (tcp-accept listener)) - (thread (lambda () (copy-port in out) - (close-output-port out))) - (echo-server)) +#lang racket ; Simple web scraper +(require net/url net/uri-codec) +(define (let-me-google-that-for-you str) + (let* ([g "http://www.google.com/search?q="] + [u (string-append g (uri-encode str))] + [rx #rx"(?<=<h3 class=\"r\">).*?(?=</h3>)"]) + (regexp-match* rx (get-pure-port (string->url u)))))
-Racket makes it easy to use TCP sockets and spawn threads to handle -them. This program starts a server at TCP port 12345 that echos -anything a client sends back to the client.
+Add a call tolet-me-google-that-for-you
to get a list of search
+results.
+
To run the example, install Racket, start DrRacket, paste the example @@ -247,11 +248,11 @@ computing and from databases to charts. - + - + @@ -264,7 +265,7 @@ computing and from databases to charts.
-#lang racket ; An echo server -(define listener (tcp-listen 12345)) -(let echo-server () - (define-values (in out) (tcp-accept listener)) - (thread (lambda () (copy-port in out) - (close-output-port out))) - (echo-server)) ++#lang racket ; Simple web scraper +(require net/url net/uri-codec) +(define (let-me-google-that-for-you str) + (let* ([g "http://www.google.com/search?q="] + [u (string-append g (uri-encode str))] + [rx #rx"(?<=<h3 class=\"r\">).*?(?=</h3>)"]) + (regexp-match* rx (get-pure-port (string->url u)))))