使用 python 向 aspx 页面提交查询并抓取结果?

发布于 2024-08-18 11:21:50 字数 1540 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鹿童谣 2024-08-25 11:21:50

也许 mechanize 可能有用。

Perhaps mechanize may be of use.

东京女 2024-08-25 11:21:50

使用 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.

不必你懂 2024-08-25 11:21:50

我使用了 请求BeautifulSoup4 用于类似的任务。

I've used a combination requests and BeautifulSoup4 for a similar task.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文