I'm trying to use Gistlabs Mechanize to do some web page processing using Scala. I've been able to figure out quite some stuff despite the fact that there is little documentation. Thankfully, there is source.
Snippets that work:
val agent= new MechanizeAgent()
agent.setUserAgent(userAgent)
val response:AbstractDocument= form.submit()
So, now I want to read through all of the cookies, so I do this. But, first let's the cookies and the class:
val cookieStore = response.getAgent().cookies().getAll()
println(cookieStore.getClass())
and I get this response:
class java.util.ArrayList
so, cookieStore is an ArrayList and I should be able to use foreach() with it, right?
When I actually try to do that:
cookieStore.foreach { println }
I get this error:
value foreach is not a member of java.util.List[com.gistlabs.mechanize.cookie.Cookie]
Clearly, I'm doing something wrong with Scala, but what?
java.util.List
has not method foreach
. But you can convert it to scala list using implicit conversion. Just add import scala.collection.convert.wrapAsScala._
to your source file.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments