【问题标题】:HowTo deal with cryptic hidden values for ASP.net? (__VIEWSTATE)如何处理 ASP.net 的神秘隐藏值? (__VIEWSTATE)
【发布时间】:2012-05-07 12:01:39
【问题描述】:

当您尝试使用 Python 请求(发布)页面时,我试图弄清楚如何处理神秘的“__VIEWSTATE”和 Cie。它是我的脚本中很多问题的主要来源......而且我意识到,当我在寻找答案/解决方案时,你没有那么多的解决方案(几乎是 0!)。

在本主题中: Unable to load ASP.NET page using Python urllib2 你可以看到我给出的解决方案包括每次加载页面时解析神秘字段的值......这有效,但实际上这很愚蠢:-)

    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)

所以这里还有一些带有很好解释的链接/一些正在提出解决方案:

What does the __VIEWSTATE hold?

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

Mechanize does not see some hidden form inputs?

Unable to load ASP.NET page using Python urllib2

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

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

(对不起,这篇文章不完美/没有完整的好信息……我很n00b,但我很努力)

【问题讨论】:

    标签: asp.net python parsing viewstate


    【解决方案1】:

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

    如果您想使用浏览器模拟某些 ASP.NET 应用程序,您需要在 POST 请求中包含那些,以便服务器可以重建页面的状态。

    它导致的确切问题是什么?我认为您的解决方案非常简单。

    顺便说一句,很多 ASP.NET 应用程序都包含公共 API,可以用来代替尝试解析它的页面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-06
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 2012-07-08
      • 2021-03-04
      • 1970-01-01
      相关资源
      最近更新 更多