Python Web Bot(urllib)

Python Web Bot(urllib),python,bots,Python,Bots,我正在尝试创建一个简单的web bot,它将访问某个页面,填写并提交表单数据,然后打印提交时重定向到的页面。但是,我的resp.read()调用会继续打印初始表单提交页面 以下是页面和我的代码: <html> <body> <P>Welcome <BR><P>Please answer the question <BR><P>98270+88340= ? <form name="loginform" me

我正在尝试创建一个简单的web bot,它将访问某个页面,填写并提交表单数据,然后打印提交时重定向到的页面。但是,我的resp.read()调用会继续打印初始表单提交页面

以下是页面和我的代码:

<html>
<body>
<P>Welcome <BR><P>Please answer the question <BR><P>98270+88340= ? 
<form name="loginform" method="post" action="vote.php">
    <input name="sum" type="text" id="sum" />
    <input type="submit" name="Submit" value="POST Answer">
    </form></body>

我使用lxml进行HTML解析。它返回正确的总和

问题解决了。。。这是一个解决方案,适合任何想看的人

import re
import mechanize
import lxml.html as lh

url='hidden'

parr=lh.parse(url).xpath('//p/text()')
elem=parr[2]
op1=int(elem[0:5])
op2=int(elem[6:11])
sum=op1+op2
print sum
sum=str(sum)

br=mechanize.Browser()
br.open(url)

br.select_form(name="loginform")
br["sum"]=sum
resp=br.submit()

br.select_form(name="poll")
br["vote"]=["7"]
resp2=br.submit()

print resp2.read()

基本上,bot会打开url,解析页面中的两个操作数,然后将总和输入表单,然后在下一页继续投票。

查看,这会使投票更容易。感谢您的建议;我和Mechaniz一起工作你应该这样做:并让它成为你自己问题的真实答案-不要删掉你的问题,它对其他人很有用!
import re
import mechanize
import lxml.html as lh

url='hidden'

parr=lh.parse(url).xpath('//p/text()')
elem=parr[2]
op1=int(elem[0:5])
op2=int(elem[6:11])
sum=op1+op2
print sum
sum=str(sum)

br=mechanize.Browser()
br.open(url)

br.select_form(name="loginform")
br["sum"]=sum
resp=br.submit()

br.select_form(name="poll")
br["vote"]=["7"]
resp2=br.submit()

print resp2.read()