We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 5 months ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
也许 mechanize 可能有用。
Perhaps mechanize may be of use.
使用 urllib2。您的 POST 数据是一个简单的 Python 字典。非常容易编辑和维护。
如果您的表单包含隐藏字段(其中一些已编码),那么您需要执行 GET 来获取表单和各种隐藏字段种子值。
获取表单后,您可以将必要的输入值添加到给定的隐藏值中,然后再次发布响应。
另外,您必须确保处理所有 cookie。 urllib2 也会对此有所帮助。
毕竟,这就是浏览器所做的一切,并且它可以在浏览器中运行。浏览器不知道 ASPX、CGI 和 WSGI,因此没有什么神奇之处,因为它是 ASPX。有时您必须在 POST 之前执行 GET 才能正确设置值和 cookie。
Use urllib2. Your POST data is a simple Python dictionary. Very easy to edit and maintain.
If your form contains hidden fields -- some of which are encoded -- then you need to do a GET to get the form and the various hidden field seed values.
Once you GET the form, you can add the necessary input values to the given, hidden values and POST the response back again.
Also, you'll have to be sure that you handle any cookies. urllib2 will help with that, also.
After all, that's all a browser does, and it works in a browser. Browser's don't know ASPX from CGI from WSGI, so there's no magic because it's ASPX. You sometimes have to do a GET before a POST to get values and cookies set up properly.
我使用了 请求 和 BeautifulSoup4 用于类似的任务。
I've used a combination requests and BeautifulSoup4 for a similar task.