从使用 AJAX 的网页获取 HTML

发布于 2024-08-21 04:53:38 字数 163 浏览 3 评论 0原文

我想知道如何抓取使用 AJAX 来获取正在呈现的网页上的内容的网页。通常,此类页面的 HTTP GET 只会获取嵌入了 JavaScript 代码的 HTML 页面。但我想知道是否可以以编程方式(最好是 Java)查询此类页面并模拟 Web 浏览器类型的请求,以便我获得 AJAX 调用后生成的 HTML 内容。

I wanted to know how to scrape web pages that use AJAX to fetch content on the web page being rendered. Typically a HTTP GET for such pages will just fetch the HTML page with the JavaScript code embedded in it. But I want to know if it is possible to programmatically (preferably Java) query for such pages and simulate a web browser kind of a request so that I get the HTML content resulting after the AJAX calls.

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

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

发布评论

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

评论(3

棒棒糖 2024-08-28 04:53:38

The Productive Programmer 中,作者 Neal Ford 建议功能测试工具Selenium 可用于非测试任务。在客户端 DOM 操作发生后检查 HTML 的任务就属于这一类。 Selenium 甚至允许您自动与浏览器交互,因此如果您需要单击一些按钮来触发某些 AJAX 事件,您可以编写脚本。 Selenium 通过使用浏览器插件和基于 java 的服务器来工作。 Selenium 测试代码(或您的情况下的非测试代码)可以用多种语言编写,包括 java、C# 和其他 .Net 语言、php、perl、python 和 ruby​​。

In The Productive Programmer author Neal Ford suggests that the functional testing tool Selenium can be used for non-testing tasks. Your task of inspecting HTML after client side DOM manipulation has taken place falls into this category. Selenium even allows you to automate interactions with the browser so if you need some buttons clicked to fire some AJAX events, you can script it. Selenium works by using a browser plugin and a java based server. Selenium test code (or non-test code in your case) can be written in a variety of languages including java, C# and other .Net languages, php, perl, python and ruby.

微凉 2024-08-28 04:53:38

您可能想查看 htmlunit

You may want to look at htmlunit

旧人九事 2024-08-28 04:53:38

当你可以两者兼得时,为什么还要选择呢? TestPlan 支持 Selenium 和 HTMLUnit 作为后端。另外,它有一种非常简单的语言来完成最常见的任务(如果需要,可以用 Java 编写扩展——这实际上很少见)。

Why choose when you can have both? TestPlan supports both Selenium and HTMLUnit as a backend. Plus it has a really simple language for doing the most common tasks (extensions can be written in Java if need be -- which is rare actually).

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