- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Re: More elegant way of reading HTML from a URL than this?
Wed, 2009-01-21, 17:43
On Wed, Jan 21, 2009 at 19:42, Seth Tisue wrote:
>>>>>> "Kenneth" == Kenneth McDonald writes:
>
> Kenneth> Here's a bit of code I wrote to read the HTML from a URL, and
> Kenneth> return it as a string. I was wondering if a Scala guru could
> Kenneth> show me the "right" way to do this. I'm sure there's a more
> Kenneth> elegant solution.
>
> def read(url:String):String =
> io.Source.fromInputStream(new java.net.URL(url).openStream()).mkString
> println(read("http://www.yahoo.com/"))
InputStream is left open?
scala.io.Source must die.
S.
On Wed, Jan 21, 2009 at 19:43, Derek Chen-Becker wrote:
> Stepan Koltsov wrote:
>> InputStreamResource.url("http://...").readString
>>
>> InputStreamResource.url("http://...").readLines
>>
>> InputStreamResource.url("http://...").lines.foreach(println(_))
>>
>> InputStreamResource is part of scalax.
>>
>> BTW, I think InputStreamResource-like classes must be included into
>> the scala standard library.
>
> I second that. Scala's included IO package is pretty anemic. At the very
> least, it would be nice to have some wrappers similar to JCL to add some
> nice scala-ish functionality to existing Java IO classes. Of course, I
> don't personally have time to work on it so I can't complain too loudly ;)
Acutually, JDK has no InputStreamResource-like classes, and it is a problem too.
S.