由于流式传输网站造成的Jsoup延迟 [英] Jsoup Delay due to Streaming Website

查看:137
本文介绍了由于流式传输网站造成的Jsoup延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关Jsoup的问题:我正在构建一个从网站获取价格的工具。但是,这个网站有流媒体内容。如果我手动浏览,我会看到20分钟前的价格,并且需要等待大约3秒才能获得当前价格。我有什么办法可以让Jsoup能够在流媒体部分获得价格方面的某种延迟?我使用这段代码:

A question regarding Jsoup: I am building a tool that fetches prices from a website. However, this website has streaming content. If I browse manually, I see the prices of 20 mins ago and have to wait about 3 secs to get the current price. Is there any way I can make some kind of delay in Jsoup to be able to obtain the prices in the streaming section? I am using this code:

conn = Jsoup.connect(link).userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36");

conn.timeout(5000);

doc = conn.get();


推荐答案

您可以使用JavaFX WebView ,并启用javascript。等待两秒后,您可以提取内容并将它们传递给JSoup。

You can Use a JavaFX WebView with javascript enabled. After waiting the two seconds, you can extract the contents and pass them to JSoup.


(After loading your url into your WebView using the example above)
String text=view.getEngine() executeScript("document.documentElement.outerHTML");
Document doc = Jsoup.parse(html);

这篇关于由于流式传输网站造成的Jsoup延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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