0
我試圖解析使用JSoup下面的HTML:jsoup NullPointerException異常
<div class="small-6 columns">
<span class="today" title="Today's weather summary for Moody">Today</span>
<div>
High
<strong class="high">27</strong>
<span class="split">|</span>
Low
<strong class="low">21</strong>
°C
</div>
...
我試圖獲取值27和21,但是當我嘗試使用下面的方法,我得到的java.lang。空指針異常。
Element temperature = doc.select("div.row collapse > strong").first();
當我使用下面的方法時,值被替換爲' - '。輸出是:今天高 - |低 - °C - %可能性Precip。
Element temperature = doc.select("span.today");
爲什麼值被替換? 它們是否由腳本填充,' - '只是HTML佔位符?
如果是的話還有另一種獲得這些值的方法嗎?
這兩種方法返回一個空字符串爲了我。我試圖解析的完整HTML是https://www.wunderground.com/cgi-bin/findweather/getForecast?query=33.593%2C-86.49&MR=1 – Ricardo
@Ricardo它看起來像JavaScript更新隊友,你在這裏有兩個選擇:1-使用像selenium這樣的java腳本下載程序2-檢查代碼並查看呼叫發生的地方和功能。 – nafas
@Ricardo像這樣: https://api.weather.com/v1/geocode/33.587719/-86.477615/forecast/daily/5day.json?language=en-US&units=e&apiKey=6532d6454b8aa370768e63d6ba5a832e – nafas