我想点击一个带有
python的按钮,该表单的信息将自动填满网页.用于向按钮发送请求的HTML代码是:

INPUT type="submit" value="Place a Bid">

我该怎么做呢?
是否可以用urllib或urllib2单击按钮?还是需要使用机械化或斜纹呢?

解决方法

使用表单目标并发送任何输入作为post数据,如下所示:

<form target="http://mysite.com/blah.php" method="GET">
    ......
    ......
    ......
    <input type="text" name="in1" value="abc">
    <INPUT type="submit" value="Place a Bid">
</form>

Python:

# parse the page HTML with the form to get the form target and any input names and values... (except for a submit and reset button)
# You can use XML.dom.minidom or htmlparser
# form_target gets parsed into "http://mysite.com/blah.php"
# input1_name gets parsed into "in1"
# input1_value gets parsed into "abc"

form_url = form_target + "?" + input1_name + "=" + input1_value
# form_url value is "http://mysite.com/blah.php?in1=abc"

# Then open the new URL which is the same as clicking the submit button
s = urllib2.urlopen(form_url)

您可以使用HTMLParser解析HTML

并且不要忘记urlencode任何发布数据:

urllib.urlencode(query)

dawei

【声明】:唐山站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。