填写文本类型的输入,然后使用python按下提交 [英] Fill input of type text and press submit using python

查看:133
本文介绍了填写文本类型的输入,然后使用python按下提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个html:

<input type="text" class="txtSearch">
<input type="submit" value="Search" class="sbtSearch">

我需要在文本字段中编写,然后单击使用python提交.输入的标记不在 Form 中.我该怎么办?

What I need is to write in the text field and then click on submit using python. The input tags are not inside Form. How I could do that?

推荐答案

您实际上不必填充字段并单击"提交.您可以模拟提交并获得所需的结果.

You shouldn't have to actually populate the fields and 'click' submit. You can simulate the submission and get the desired results.

在Firefox中将 BeautifulSoup 和urllib一起使用.使用firebug观察网络流量,并从提交正在执行的HTTP POST中获取post参数.创建字典并对其进行网址编码.将其与您的网址请求一起传递.

Use BeautifulSoup and urllib alongside firebug in Firefox. Watch the network traffic with firebug, and get the post parameters from the HTTP POST that the submit is doing. Create a dict and url-encode it. Pass it alongside your url request.

例如:

from BeautifulSoup import BeautifulSoup
import urllib

post_params = {
    param1 : val1,
    param2 : val2,
    param3 : val3
        }
post_args = urllib.urlencode(post_params)

url = 'http://www.website.com/'
fp = urllib.urlopen(url, post_args)
soup = BeautifulSoup(fp)

参数vals将根据您尝试提交的内容而改变.在代码中进行适当调整.

The parameter vals will change according to what you're attempting to submit. Make appropriate accommodations in your code.

这篇关于填写文本类型的输入,然后使用python按下提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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