如何处理ASP.net的隐式隐藏值?(__VIEWSTATE) [英] HowTo deal with cryptic hidden values for ASP.net? (__VIEWSTATE)

查看:54
本文介绍了如何处理ASP.net的隐式隐藏值?(__VIEWSTATE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚如何处理神秘的"__VIEWSTATE"消息.&当您尝试使用Python请求(发布)页面时,请选择Cie.这是我脚本中很多问题的主要根源……当我寻找答案/解决方案时,我意识到您没有那么多解决方案(几乎为0!).

I was trying to figure out how to deal with the cryptic "__VIEWSTATE" & Cie when you are trying to request (POST) a page with Python. It is the main source of a lot of problems in my scripts ... and I realize, when I was looking for answers / solutions, that you don't have that much of solutions (almost 0 !).

在本主题中:无法使用Python urllib2加载ASP.NET页面您可以看到,每次加载页面时,我都在通过对大陆字段的值进行解析来为我提供解决方案……这是可行的,但实际上这很愚蠢:-)

In this topic: Unable to load ASP.NET page using Python urllib2 You can see that I am giving my solution with consist in parsing the value of the cryptic fields every time you load the page ... That works, but that's quite stupid actually :-)

    for result in the_page.findAll('input', attrs={'name' : '__VIEWSTATE'}):
        view_state =  result['value']

    for result_1 in the_page.findAll('input', attrs={'name' : '__EVENTVALIDATION'}):
        event_validation =  result_1['value']

    for result_2 in the_page.findAll('input', attrs={'name' : '__PREVIOUSPAGE'}):
        previous_page =  result_2['value']

    for result in the_page.findAll('input', attrs={'name' : '__EVENTTARGET'}):
        event_target =  result['value']

之后:

    url = 'http://bandscore.ielts.org/search.aspx'
    values = {
                            '__EVENTTARGET' : 'gdvSearchResults',
                            '__EVENTARGUMENT' : page,
                        '__VIEWSTATE' : view_state,
                        '__PREVIOUSPAGE' : previous_page,
                        '__EVENTVALIDATION' : event_validation,
                        'DropDownList1'  : Country,
                        #'txtSearchInstitution'  : '',
                        #'hdnSearchText'  : '',
                        #'rdoFilter': '%25',
    }
    user_agent = 'Mozilla/5 (Solaris 10) Gecko'
    headers = { 'User-Agent' : user_agent }
    data = urllib.urlencode(values)
    req = urllib2.Request(url, data, headers)
    response = urllib2.urlopen(req)
    thePage = response.read()
    the_page = soup(thePage)

因此,这里还有一些链接有很好的解释/一些正在提出解决方案:

So here few more links with good explanations / some are proposing solutions:

__VIEWSTATE拥有什么?

> http://aspalliance.com/articleViewer.aspx?aId=135&pId =

http://msdn.microsoft.com/en-us/library/system.web.ui.losformatter.aspx

http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx

http://msdn.microsoft.com/en-us/library/ms972976.aspx

机械化没有看到一些隐藏的表单输入吗?

无法使用Python urllib2加载ASP.NET页面

我意识到很多人都在试图找到一种解决此问题的好方法,所以让我们一起努力寻找一个好的解决方案;-)

I realize that a lot of people are trying to find a good way to deal with that, so let's try to find a good solution, all together ;-)

EDIT1 :发现也很有趣, http://code.google.com/p/peekviewstate/source/browse/trunk/src/peekviewstate_example.py

(很抱歉,这篇帖子不够完善/缺少很多很好的信息……我相当n00b,但是我努力了)

(Sorry is this post in not perfect / full of good info ... I'm quite a n00b but I try hard)

推荐答案

如何处理?只需将 __ VIEWSTATE 视为服务器发送给您的不透明数据即可.它包含给定页面及其对象状态的一些特定数据,我不建议您对其进行修改.

How to deal with it? Just think of __VIEWSTATE as opaque data sent to you by the server. It contains some specific data for given page and state of it's objects, and I don't really recommend you to modify it.

如果要使用浏览器模拟某些ASP.NET应用程序,则需要在 POST 请求中包括这些内容,以便服务器可以重建页面状态.

If you want to emulate using browser for some ASP.NET application, you need to include those ones in POST request, so the server can reconstruct page's state.

造成的确切问题是什么?我认为您的解决方案非常简单.

What are exact problem it is causing? I think that your solution is pretty straightforward.

顺便说一句,请注意-许多ASP.NET应用程序都包含公共API,可以使用它代替尝试解析其页面.

Btw, just on a side note - lot of ASP.NET application contains public API, which can be used instead of trying to parse it's pages.

这篇关于如何处理ASP.net的隐式隐藏值?(__VIEWSTATE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆