learning F#, it seems pretty cool, favourite functional language so far.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

downloadWebpage.fsx 727B

1234567891011121314151617181920212223
  1. open System.Net
  2. open System
  3. open System.IO
  4. let fetchUrl cb url =
  5. let req = WebRequest.Create(Uri(url))
  6. use resp = req.GetResponse()
  7. use stream = resp.GetResponseStream()
  8. use reader = new IO.StreamReader(stream)
  9. cb reader url
  10. let myCb (reader:IO.StreamReader) url =
  11. let html = reader.ReadToEnd()
  12. let html1000 = html.Substring(0,1000)
  13. printfn "Downloaded %s. First 1000 is %s" url html1000
  14. html
  15. // let blog = fetchUrl myCb "https://blog.etopiei.com"
  16. // This could also be written `point free` but I like the explicitness
  17. let generalPageDownload url = fetchUrl myCb url
  18. generalPageDownload "https://google.com"
  19. generalPageDownload "https://etopiei.com"