python mechanize返回错误的302位置

python mechanize返回错误的302位置,python,mechanize,Python,Mechanize,我试图做一些自动化的网站,但访问搜索页面,我需要的pid是在服务器上生成的。 我寻找浏览器做出的响应,并尝试在python中使用mechanize进行同样的操作 import mechanize; import cookielib; import urllib2; import lxml.html; br = mechanize.Browser() cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) br.set_handle_equiv(T

我试图做一些自动化的网站,但访问搜索页面,我需要的pid是在服务器上生成的。 我寻找浏览器做出的响应,并尝试在python中使用mechanize进行同样的操作

import mechanize;
import cookielib;
import   urllib2;
import lxml.html;
br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(False)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1'),('Referer', 'http://www.beistle.com/'), ('Connection', 'keep-alive'), ('Host','www.beistle.com'), ('Accept-Language', 'en-US,en;q=0.5'), ('Accept-Encoding', 'gzip, deflate'), ('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8') ]
br.set_debug_http(True)
br.set_debug_redirects(True)
br.set_debug_responses(True)
br.open("http://www.beistle.com/");
br.select_form(name='aspnetForm');
br.submit();

在浏览器中,它返回302,其中包含写入pid的正确位置。然而,mechanize返回的“Location:/Search.aspx”不能用于搜索

看起来在
submit
按钮的点击事件背后有很多js逻辑(请参见
WebForm\u DoPostBackWithOptions
函数)。顺便问一下,您可以切换到selenium吗?我来看看selenium,谢谢