headzoo / surf

Stateful programmatic web browsing in Go.
MIT License
1.48k stars 159 forks source link

Proposal: A way to make contrived forms #9

Closed mholt closed 9 years ago

mholt commented 9 years ago

Really enjoying surf so far. However, as mentioned in the TODO section of the readme, surf doesn't execute JavaScript. One of my projects right now involves logging in on a site where the login form is injected into the page by JavaScript. I can use the network inspector in Chrome to see what the form submit looks like, but the trouble is getting the form into the DOM for a browser that doesn't support JavaScript.

One thought I had would be to contrive a form that doesn't actually exist on the DOM but is submittable all the same. Basically, the user would invoke surf.NewFakeForm(action, method) which acts like a regular surf.Form except that methods like Input(name, value) don't check to make sure name already exists (it would create it).

Basically, the Form type might become an interface.

Would you accept a pull request that adds this functionality? And I'm still kind of new to this package, so if you know of a better way to accomplish what I need to do, feel free to let me know!

girishso commented 9 years ago

+1 I would like to have FakeForm.

@mholt if you don't mind taking a shortcut you can try browser.PostForm(u string, data url.Values)

mholt commented 9 years ago

I missed that possibility - thanks! I'll give it a go and report back.

mholt commented 9 years ago

Aha, that did the trick well enough. That's a much simpler way to do it; thanks again @girishso.