ArrayList in Scala with Gistlabs Mechanize. Unable to use foreach

adele dazim

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?

Sergii Lagutin

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to use arraylist parameter in java

From Dev

Unable to gem install mechanize

From Dev

Unable to gem install mechanize

From Dev

LitJSON: Unable to use foreach in Unity

From Dev

Unable to use java code in scala

From Dev

Mechanize: Unable to redirect to final destination

From Dev

Use mechanize to submit form data

From Dev

How to use Mechanize on a page with no form?

From Dev

When to use fold and when to use foreach in list in Scala

From Dev

Unable to submit Amazon form via Mechanize (Ruby)

From Dev

Unable to use forEach in Flutter Dart for array with just Strings

From Dev

Unable to use Viewbag List Items in Razor foreach loop

From Dev

Unable to use forEach in Flutter Dart for array with just Strings

From Dev

Unable to use Viewbag List Items in Razor foreach loop

From Dev

Use python mechanize to log into pages with NTLM authentication

From Dev

Use perl WWW::Mechanize on a local file

From Dev

how can I use mechanize python in java

From Dev

Unable to use scala's repl :javap to look at trait companion object

From Dev

Java ForEach in ArrayList with Locate

From Dev

Mechanize unable to navigate KBB.com, get Mechanize::ResponseCodeError: 500 => Net::HTTPInternalServerError

From Dev

Mechanize unable to navigate KBB.com, get Mechanize::ResponseCodeError: 500 => Net::HTTPInternalServerError

From Dev

Mechanize search unable to find CSS selector (it's definitely present)

From Dev

Unable to output ArrayList contents

From Dev

Unable to add an element to an arraylist

From Dev

Unable to add to an object into ArrayList

From Dev

Unable to populate ListView with ArrayList

From Dev

Unable to add an element to an arraylist

From Dev

Java's "forEach" to Scala

From Dev

Scala foreach member variable

Related Related

  1. 1

    Unable to use arraylist parameter in java

  2. 2

    Unable to gem install mechanize

  3. 3

    Unable to gem install mechanize

  4. 4

    LitJSON: Unable to use foreach in Unity

  5. 5

    Unable to use java code in scala

  6. 6

    Mechanize: Unable to redirect to final destination

  7. 7

    Use mechanize to submit form data

  8. 8

    How to use Mechanize on a page with no form?

  9. 9

    When to use fold and when to use foreach in list in Scala

  10. 10

    Unable to submit Amazon form via Mechanize (Ruby)

  11. 11

    Unable to use forEach in Flutter Dart for array with just Strings

  12. 12

    Unable to use Viewbag List Items in Razor foreach loop

  13. 13

    Unable to use forEach in Flutter Dart for array with just Strings

  14. 14

    Unable to use Viewbag List Items in Razor foreach loop

  15. 15

    Use python mechanize to log into pages with NTLM authentication

  16. 16

    Use perl WWW::Mechanize on a local file

  17. 17

    how can I use mechanize python in java

  18. 18

    Unable to use scala's repl :javap to look at trait companion object

  19. 19

    Java ForEach in ArrayList with Locate

  20. 20

    Mechanize unable to navigate KBB.com, get Mechanize::ResponseCodeError: 500 => Net::HTTPInternalServerError

  21. 21

    Mechanize unable to navigate KBB.com, get Mechanize::ResponseCodeError: 500 => Net::HTTPInternalServerError

  22. 22

    Mechanize search unable to find CSS selector (it's definitely present)

  23. 23

    Unable to output ArrayList contents

  24. 24

    Unable to add an element to an arraylist

  25. 25

    Unable to add to an object into ArrayList

  26. 26

    Unable to populate ListView with ArrayList

  27. 27

    Unable to add an element to an arraylist

  28. 28

    Java's "forEach" to Scala

  29. 29

    Scala foreach member variable

HotTag

Archive