【问题标题】:How to get the value of a variable from parsed HTML using Jsoup如何使用 Jsoup 从解析的 HTML 中获取变量的值
【发布时间】:2016-08-14 01:51:54
【问题描述】:

我正在使用 Jsoup 来获取 weather station 的 html。当我在天气页面上并右键单击该页面并检查它时,在 DOM 中我看到了我想要的元素,即

<span data-gm-wx-temperature="::todayWxcardVm.obs.temperature" data-text-to-replace="77"><!-- ngIf: tempPrefix --> <!-- ngIf: hasValue --><span data-ng-if="hasValue" class="dir-ltr" data-ng-bind="temp | safeDisplay">77</span><!-- end ngIf: hasValue --><!-- ngIf: hasValue --><sup data-ng-if="hasValue" class="deg dir-ltr">°</sup><!-- end ngIf: hasValue --><!-- ngIf: showTempUnit -->
    <!-- ngIf: !hasValue --></span>

我希望能够在 data-text-to-replace ="77" 中获取温度值,但我的问题是 Jsoup 向我返回这个:

<span data-gm-wx-temperature="::todayWxcardVm.obs.temperature" data-text-to-replace="{{ '[[ obs.temperature ]]'.indexOf('\[\[') !== -1 ? '--' : '[[ obs.temperature ]]' }}">[[ obs.temperature ]]</span>

在哪里,而不是 data-text-to-replace="77" 我得到 data-text-to-replace={{ '[[ obs.temperature ]] }}' 我假设是角度.js 变量网站的创建者用来存储温度的值。

如何获得 obs.temperature 的实际值?

【问题讨论】:

  • 你当前使用什么代码来提取你想要的值?
  • 可能duplicate

标签: java angularjs jsoup


【解决方案1】:

您无法提取温度值的原因是它不是从weather.comHTML 中发送的。相反,它使用通过AJAX 调用api.weather.com 获得的值在客户端填充。

您可以从 Java 客户端直接调用此 Web 服务,但 我认为这不构成对该服务的合法使用,因为我可以在服务输入中看到 API Key

以下是带有weather.com API 密钥的示例 Web 服务请求。

https://api.weather.com/v2/turbo/vt1precipitation;vt1currentdatetime;vt1pollenforecast;vt1dailyForecast;vt1observation?units=e&language=en-US&geocode=30.51,-97.68&format=json&apiKey=c1ea9f47f6a88b9acb43aba7faf389d4

如果我们说outputJSON 响应,那么下面会给你温度。

output.vt1observation.feelsLike

下面是一个示例output.vt1observation

{
   "altimeter":29.86,
   "barometerTrend":"Rising",
   "barometerCode":1,
   "barometerChange":0.01,
   "dewPoint":74,
   "feelsLike":77,
   "gust":null,
   "humidity":91,
   "icon":29,
   "observationTime":"2016-08-13T21:05:00-0500",
   "obsQualifierCode":null,
   "obsQualifierSeverity":null,
   "phrase":"Partly Cloudy",
   "precip24Hour":0.29,
   "snowDepth":0.0,
   "temperature":77,
   "temperatureMaxSince7am":97,
   "uvIndex":0,
   "uvDescription":"Low",
   "visibility":10.000,
   "windSpeed":1,
   "windDirCompass":"N",
   "windDirDegrees":0
}

【讨论】:

    猜你喜欢
    • 2013-07-29
    • 2023-03-31
    • 2019-12-23
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 2012-09-14
    • 1970-01-01
    • 2018-11-19
    相关资源
    最近更新 更多