Python-单击javascript按钮 [英] Python - clicking a javascript button

查看:268
本文介绍了Python-单击javascript按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上有一个按钮,需要单击该按钮才能按顺序进入下一页,而我想知道Python如何做到这一点.该按钮似乎是HTTP POST请求和Javascript的混合,这是该按钮的代码:

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.

推荐答案

要模拟表单的提交,您可以发送与单击提交按钮后浏览器将发送到站点的相同POST请求.一种方法是使用urllib.urlencode对字典中的表单数据进行编码,然后使用urllib2.urlopen发送请求:

To 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)

这篇关于Python-单击javascript按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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