aspx Web ページに投稿しようとしています。ログインに成功しましたが、ページのコンテンツを取得しようとしましたが、うまくいきませんでした。
ページにログインすると、redirect
tmp.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>
</form>
</body>