Java-用JSoup 抓取动态网站 [英] Java-Scrape a dynamic website with JSoup

查看:34
本文介绍了Java-用JSoup 抓取动态网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 JSoup 抓取一个网站.该网站是动态的,每秒钟左右更新一次.我很确定它使用了 JQuery,它更新了 HTML 中的一些标签.我正在使用 JSoup,但动态区域是空白的.JSoup 有什么特别的方法可以解决这个问题吗?或者这是一个限制?我打算把它放在我网站上的 Java 小程序中.

I would like to scrape a website with JSoup. This website is dynamic and updates every second or so. I'm pretty sure it uses JQuery, which updates some tags in the HTML. I'm using JSoup, but the dynamic areas that are blank. Does JSoup have anything special to fix this problem? Or is this a limitation? I'm planning to put this in a Java applet on my website.

推荐答案

听起来您希望 JSoup 表现得像一个支持 JavaScript 的浏览器.恐怕不行.JSoup 是一个工具,可以执行 HTTP 请求,然后将响应正文用于有用的东西.

Sounds like you want JSoup to behave like a browser with JavaScript support. That won't work, I'm afraid. JSoup is a tool that can execute a HTTP request, and then use the response body for something useful.

这个有用的东西"是从响应中的 (X)HTML 文本中提取信息.如果您想在加载了 JavaScript 注入的 HTML 页面(=动态网页)之后获取后续 ajax 请求的内容,您需要自己对这些后续请求进行建模,并指示 JSoup 为您手动执行这些请求.

This 'something useful' is to extract information from the (X)HTML text in the response. If you want to the contents of subsequent ajax-request following the loading of a JavaScript-infused HTML page (=dynamic web page) you'll need to model those follow-up requests yourself and instruct JSoup to execute those for you manually.

这篇关于Java-用JSoup 抓取动态网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆