如何填写表格 [英] How to fill a form

查看:65
本文介绍了如何填写表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从网站填写表格,这个表格的代码看起来像

这个:


< form action =" login。 PHP"方法= QUOT;交" target =" _top">


< input type =" text"命名= QUOT;用户名"大小= QUOT; 25" maxlength =" 40"

class =" post" />

< input type =" password"名称= QUOT;密码"大小= QUOT; 25" maxlength =" 25"

class =" post" />


< input type =" hidden" name =" redirect"

value ="" />

< input type =" submit"名称= QUOT;登录" class =" mainoption"

value ="登录" />


< / form>


我当然可以连接到网站并下载表格,我这样做

是这样的:


import urllib2

www = urllib2.urlopen(" http://www.site.com/ login.php")

form_data = stronka.read()


或使用httplib:


import httplib

conn = httplib.HTTPConnection(" www.site.com")

conn.request(" GET"," /login.php")

data1 = conn.getresponse()。read()

但是我无法填写并发送此表格有一些简单的方法吗?

解决方案

Sulsa写道:


我需要从网站填写表格,这个表格的代码看起来比如

这个:


< form action =" login.php"方法= QUOT;交" target =" _top">


< input type =" text"命名= QUOT;用户名"大小= QUOT; 25" maxlength =" 40"

class =" post" />

< input type =" password"名称= QUOT;密码"大小= QUOT; 25" maxlength =" 25"

class =" post" />


< input type =" hidden" name =" redirect"

value ="" />

< input type =" submit"名称= QUOT;登录" class =" mainoption"

value ="登录" />


< / form>


我当然可以连接到网站并下载表格,我这样做

是这样的:


import urllib2

www = urllib2.urlopen(" http://www.site.com/ login.php")

form_data = stronka.read()


或使用httplib:


import httplib

conn = httplib.HTTPConnection(" www.site.com")

conn.request(" GET"," /login.php")

data1 = conn.getresponse()。read()


但是我无法填写并发送此表格是否有一些简单的方法可以做到这一点?



我建议你看看机械化,请参阅

http://wwwsearch.sourceforge.net/mechanize/

,特别是在ClientForm,请参阅

http://wwwsearch.sourceforge.net/ClientForm/


这样可以轻松地对基于表单的网页执行类似浏览器的访问

应用程序。


问候

Steve

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC / Ltd http://www.holdenweb.com

Skype:holdenweb http://holdenweb.blogspot.com

最近的Ramblings http://del.icio.us/steve.holden

On Tue,2006年8月15日03:22:40 +0100

Steve Holden< st *** @ holdenweb.comwrote:


我建议你看看机械化,请参阅

http://wwwsearch.sourceforge.net/mechanize/


,特别是在ClientForm,请参阅

http://wwwsearch.sourceforge.net/ClientForm/


这样可以轻松地对基于表单的

Web应用程序执行类似浏览器的访问。



我想只填写一个smiple form所以我不想使用任何非
标准库。


2006-08-15,Sulsa< su ** *@gazeta.plwrote:

我想只填写一个smiple表单,所以我不想使用

任何非标准库。



然后只需发送HTTPPOST即可。请求包含字段

和您要提交的数据。


-

Grant Edwards grante哇! LBJ,LBJ,你今天告诉JOKES多少

??!

visi.com


I need to fill form from web site, the code for this form looks like
this:

<form action="login.php" method="post" target="_top">

<input type="text" name="username" size="25" maxlength="40"
class="post" />
<input type="password" name="password" size="25" maxlength="25"
class="post" />

<input type="hidden" name="redirect"
value="" />
<input type="submit" name="login" class="mainoption"
value="Login" />

</form>

I can of course connect to a web site and download the form, i do it
like this:

import urllib2
www = urllib2.urlopen("http://www.site.com/login.php")
form_data= stronka.read()

or using httplib:

import httplib
conn = httplib.HTTPConnection("www.site.com")
conn.request("GET", "/login.php")
data1 = conn.getresponse().read()
but i can''t fill and send this form is there some simple way to do it?

解决方案

Sulsa wrote:

I need to fill form from web site, the code for this form looks like
this:

<form action="login.php" method="post" target="_top">

<input type="text" name="username" size="25" maxlength="40"
class="post" />
<input type="password" name="password" size="25" maxlength="25"
class="post" />

<input type="hidden" name="redirect"
value="" />
<input type="submit" name="login" class="mainoption"
value="Login" />

</form>

I can of course connect to a web site and download the form, i do it
like this:

import urllib2
www = urllib2.urlopen("http://www.site.com/login.php")
form_data= stronka.read()

or using httplib:

import httplib
conn = httplib.HTTPConnection("www.site.com")
conn.request("GET", "/login.php")
data1 = conn.getresponse().read()
but i can''t fill and send this form is there some simple way to do it?

I''d recommend you take a look at mechanize, see

http://wwwsearch.sourceforge.net/mechanize/

and specifically at ClientForm, see

http://wwwsearch.sourceforge.net/ClientForm/

These make it easy to perform browser-like accesses to forms-based web
applications.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden


On Tue, 15 Aug 2006 03:22:40 +0100
Steve Holden <st***@holdenweb.comwrote:

I''d recommend you take a look at mechanize, see

http://wwwsearch.sourceforge.net/mechanize/

and specifically at ClientForm, see

http://wwwsearch.sourceforge.net/ClientForm/

These make it easy to perform browser-like accesses to forms-based
web applications.

I want to fill only one smiple form so i would like not to use any non
standard libraries.


On 2006-08-15, Sulsa <su***@gazeta.plwrote:

I want to fill only one smiple form so i would like not to use
any non standard libraries.

Then just send the HTTP "POST" request containing the fields
and data you want to submit.

--
Grant Edwards grante Yow! LBJ, LBJ, how many
at JOKES did you tell today??!
visi.com


这篇关于如何填写表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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