Web Automation - Dealing with .aspx

百般思念 提交于 2021-01-27 17:20:25

问题


I'm trying to accomplish a little bit of automation which includes submitting a form on a webpage. The values for the form are already coded per item in the list.

I've tried many different modules with Python and nothing seems to give me an answer. I don't have access to Visual Basic and I've personally never dealt with .aspx pages before. This is the Form name And I thought I was set and ready to go when I found the parameters for the form: function ShowEditForm(id, param1, param2, param3, param4) #actual parameter names removed for security

And this is the part that's the major headache:

<INPUT id=__EVENTTARGET type=hidden name=__EVENTTARGET> <INPUT id=__EVENTARGUMENT     type=hidden name=__EVENTARGUMENT> <INPUT id=__VIEWSTATE type=hidden value=/wEPDw... #This     continues for 800+ characters

I believe this is the cause of my failure of code, am I on a witchhunt trying to post to an .aspx form in python?

Thanks


回答1:


you would need to parse/parameterize your post headers and contents. this can be non-trivial.

check out mechanize for access at the HTTP level, with some form handling convenience.

check out selenium, for driving a real browser in Python.




回答2:


I don't think aspx has anything to do with it.

Have you tried http://pypi.python.org/pypi/selenium ?




回答3:


Indeed, the server-side handling of the POST request won't work if those hidden values aren't present. ASP.NET uses that stuff to track statefulness across multiple requests. Reverse-engineering ASP.NET Web Forms HTTP requests isn't a fun endeavor.

You'll probably need to request the page, scrape the hidden values it gives you, and include those in the POST.

Stepping through a manual interaction with the page and capturing requests/responses in something like FireBug will also give you a good idea of the values being sent back and forth between the client and the server. It wouldn't surprise me if there's some JavaScript emitted to the response which dynamically modifies some hidden fields in server-pre-determined ways as well, helping to indicate which button was pressed or which control was in some way modified.




回答4:


Asp.net has a feature called viewstate (encrypted page state settings) which you can't fake, and which the page may be using by default and will expect to see on post to the form when submitting back to itself (called post back).

If you control the .aspx code it likely has an associated .cs or .vb file with the code to do the form processing. You can change the code to get values from posted form or URL parameters instead of (or in addition to) controls on the original form. If the site is compiled and you don't see any .vb or .cs files to change you would need to locate the original source files for the solution.



来源:https://stackoverflow.com/questions/12645849/web-automation-dealing-with-aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!