1

我正在尝试在 aspx 网页上发帖。我已成功完成登录并尝试获取页面内容但没有运气。

登录页面后转到redirecttmp.aspx,然后它会向您显示主页。

我的代码当前登录并显示 tmp.aspx。我想要的是显示真实页面的脚本。

所以当前流程 login->tmp(display) 我要的流程 login->tmp->default(display)

import lxml.html
import requests
starturl = 'http://*/login.aspx'
s = requests.session() # create a session object
r1 = s.get(starturl) #get page 1
html = r1.text
root = lxml.html.fromstring(html)

#pick up the javascript values
EVENTVALIDATION = root.xpath('//input[@name="__EVENTVALIDATION"]')[0].attrib['value']
#find the __EVENTVALIDATION value
VIEWSTATE = root.xpath('//input[@name="__VIEWSTATE"]')[0].attrib['value']
#find the __VIEWSTATE value
# build a dictionary to post to the site with the values we have collected. The __EVENTARGUMENT can be changed to fetch another result page (3,4,5 etc.)
payload = {'__EVENTTARGET':'TransactBtn','__EVENTARGUMENT':'','__EVENTVALIDATION':EVENTVALIDATION,'__VIEWSTATE':VIEWSTATE,'AccountID':'557','UserName':'*','Password':'*'}

# post it
r2 = s.post(starturl, data=payload)
# our response is now page 2
print r2.text

请指教?谢谢

tmp.aspx 源代码。(这是我执行脚本时显示的内容)

<body>
    <form name="form1" method="post" action="tmp.aspx" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZCOgyU+AdP30f85W4DdUIV6LnCqa" />

    <script type="text/javascript">
        top.location.href = document.location.href;               
        document.forms["form1"].submit();        
    </script>
        &nbsp;&nbsp;</form>
</body>
4

0 回答 0