方法文档处理的ASP净神秘的隐藏值(__VIEWSTATE) [英] HowTo deal with cryptic hidden values for ASP Net (__VIEWSTATE)

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

问题描述

Hey Guys,

我试图找出如何对付神秘__VIEWSTATE&放大器;当你试图请求(POST)的网页与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's 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 !).

本主题:
<一href=\"http://stackoverflow.com/questions/5380638/unable-to-load-asp-net-page-using-python-urllib2\">Unable使用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 /库/ 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

<一个href=\"http://stackoverflow.com/questions/3338214/mechanize-does-not-see-some-hidden-form-inputs\">Mechanize没有看到一些隐藏的表单输入?

<一个href=\"http://stackoverflow.com/questions/5380638/unable-to-load-asp-net-page-using-python-urllib2\">Unable使用装载ASP.NET页面的Python的urllib2

我知道有很多人正在努力寻找一个好的方法来处理这​​一点,所以让我们尝试找到一个很好的解决方案,都在一起; - )

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://$c$c.google.com/p/peekviewstate/source/browse/trunk/src/peekviewstate_example.py

EDIT1: Found that too, might be interesting 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.

什么是确切的问题,这是造成?我认为您的解决方案是pretty简单。

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净神秘的隐藏值(__VIEWSTATE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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