[英]java get element from webpage into variable
I'm trying to get an element from a page into a variable我正在尝试将页面中的元素放入变量中
String url = "http://www.aaaaaaa.com";
Document document = Jsoup.connect(url).get();
String value = document.body().select("").get(0).text();
how to get this into the value如何将其转化为价值
<div class="clock-text">12:10:13 pm</div>
If you know the element you're trying to retrieve will always have the class clock-text
then you have to change the last line to:如果您知道您要检索的元素将始终具有 class clock-text
,那么您必须将最后一行更改为:
String value = document.body().select(".clock-text").get(0).text()
JSoup's select method works with CSS queries. JSoup 的 select 方法适用于 CSS 查询。
Selector based on div with class name clock-text
基于名称为 class 的 div 的选择器clock-text
Elements element = document.select("div.clock-text").first();
The first
matched element, or null
if contents is empty.第first
匹配的元素,如果内容为空, null
。
String value = element.text();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.