简体   繁体   English

使用 JSoup 解析特定元素

[英]Parsing a specific element using JSoup

I'm wondering if anyone is familiar with parsing a specific part of a website's HTML, such as getting a current temperature or current conditions from a website using JSoup ?我想知道是否有人熟悉解析网站 HTML 的特定部分,例如使用JSoup从网站获取当前温度或当前条件? I've searched all over and it seems like all the examples are people using for each loops to extract a list.我到处搜索,似乎所有示例都是人们使用 for 每个循环来提取列表的。 For example in the picture I attached, I only want to parse the -3 degrees into my IDE.例如在我附上的图片中,我只想将-3度解析到我的IDE中。 Any help would be greatly appreciated!任何帮助将不胜感激! Thanks!谢谢!

Picture:图片:

1

You should be able to use standard selectors to get the data you want from the Document.select() method.您应该能够使用标准选择器从Document.select()方法中获取所需的数据。 The easiest way to get this would be to open the web page in your browser's inspector, inspect that element specifically, then context-click its node in the element viewer and select Copy -> Selector Path.最简单的方法是在浏览器的检查器中打开网页,专门检查该元素,然后在元素查看器中上下文单击其节点并选择复制 -> 选择器路径。

Personally, I've experienced pretty substantial trouble with JSoup and have found that injecting artoo.js is usually a quicker way to get what I want out of a page regardless of environment.就我个人而言,我在使用 JSoup 时遇到了相当大的麻烦,并且发现注入artoo.js通常是一种无论环境如何都可以更快地从页面中获取所需内容的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM