Reputation: 8888
I am trying to write a website crawler with Mechanize
, and I found that my target website is written in a SPA fashion, and although there are a bunch of text fields and buttons, there is no form!
How can I use mechanize
to fill text fields and click buttons outside forms?
Upvotes: 3
Views: 638
Reputation: 54984
Let's say agent
is a Mechanize
object and page
is a Mechanize::Page
.
You can do:
form = Mechanize::Form.new page.at('body'), agent
Now the form is initialized with all the fields and buttons on the page.
You will need to set the action and method yourself:
form.action = 'http://foo.com'
form.method = 'POST'
next_page = form.submit
Upvotes: 0
Reputation: 132
I had the exact same problem you did. I ended up using 'capybara', 'launchy' and 'selenium-webdriver' to do what 'mechanize' would have in non-JavaScript env
Upvotes: 3