admin管理员组文章数量:1315310
I have a button on a page that needs to be clicked for me to move on to the next page in a sequence, and I was wondering how this is possible with Python. The button seems to be the mix of an HTTP POST request and Javascript, here is the code for the button:
<FORM name="ff" action="nq2.phtml" method="post">
<INPUT type="hidden" name="target" value="-1">
<INPUT type="hidden" name="fact" value="">
<INPUT type="hidden" name="parm" value="">
<INPUT type="hidden" name="use_id" value="-1">
<INPUT type="hidden" name="nxactor" value="1">
<TD align="center" valign="top">
<DIV class="pr">
<A href="javascript:;" onClick="settarget(5); setch(ch5); return false;">
I honestly have no idea how to approach something like this and was wondering if anyone had some insight about how I would go about doing it.
I have a button on a page that needs to be clicked for me to move on to the next page in a sequence, and I was wondering how this is possible with Python. The button seems to be the mix of an HTTP POST request and Javascript, here is the code for the button:
<FORM name="ff" action="nq2.phtml" method="post">
<INPUT type="hidden" name="target" value="-1">
<INPUT type="hidden" name="fact" value="">
<INPUT type="hidden" name="parm" value="">
<INPUT type="hidden" name="use_id" value="-1">
<INPUT type="hidden" name="nxactor" value="1">
<TD align="center" valign="top">
<DIV class="pr">
<A href="javascript:;" onClick="settarget(5); setch(ch5); return false;">
I honestly have no idea how to approach something like this and was wondering if anyone had some insight about how I would go about doing it.
Share Improve this question edited Jan 19, 2012 at 7:19 jcollado 40.4k9 gold badges107 silver badges137 bronze badges asked Jan 19, 2012 at 7:02 Dan DoeDan Doe 1,1663 gold badges14 silver badges25 bronze badges 3- What does settarget() function do? Anyway you can't do it with Python but you have to do it with javascript (with a setTimeout() if you need delay). – Fabio Buda Commented Jan 19, 2012 at 7:10
- @FabioBuda Apparently you can! ;) – HarryCBurn Commented Oct 27, 2014 at 17:50
- How did you get the code for this button? Wireshark? – Yu Zhang Commented Feb 2, 2017 at 7:31
1 Answer
Reset to default 6To simulate the submission of a form, you can send the same POST request that your browser will send to the site once the submit button is clicked. One way to do this is use urllib.urlencode
to encode the form data from a dictionary and urllib2.urlopen
to send the request:
import urllib, urllib2
form_data = urllib.urlencode({'target': <value>, 'fact': <value>, ...})
urllib2.urlopen("np2.phtml", form_data)
本文标签: Pythonclicking a javascript buttonStack Overflow
版权声明:本文标题:Python - clicking a javascript button - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741978710a2408272.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论