天氣預報的獲取

2022-04-08 10:52:20 字數 2221 閱讀 1155

好久沒有寫技術文章了,2023年工作太忙,奔波在國內各地,也沒什麼時間關注一些技術方面的事情,最近有乙個專案封閉開發,有些時間來寫些瑣碎的東西,就當是整理下最近的東西吧,沒什麼技術價值,純粹玩玩而已。

本篇是獲取qq天氣預報資訊,獲取的是杭州的當天天氣,如果需要獲取未來三天以及其他城市的,做成配置即可,本人比較懶,簡單的做該做的就ok了,下面是**實現部分,純粹抓取,沒使用正則匹配,以前做過乙個星座獲取的,有時間的話一會一起貼下。

抓取天氣資訊部分

1///

2///

返回天氣arraylist

3///

[0]日期

4///

[1]白天天氣

5///

[2]夜晚天氣

6///

[3]白天天氣描述

7///

[4]夜晚天氣描述

8///

[5]白天天氣溫度

9///

[6]夜晚天氣溫度

10///

11///

12private

arraylist qqweather()

1344

else

4549

if(temperature.indexof("~

") !=-

1)5054

else

5559

60arr.add(date);

61arr.add(dayweatherimage);

62arr.add(nightweatherimage);

63arr.add(dayweatherdescription);

64arr.add(nightweatherdescription);

65arr.add(daytemperature);

66arr.add(nighttemperature);

6768

return

arr;69}

擷取的方法

字串擷取

1///

2///

字元擷取

3///

4///

源字串5///

起始字元

6///

結束字元

7///

8private

string

subhtml(

string

data, 

string

f, stringb)9

17index 

=data.indexof(b, startindex);

18if

(index ==-

1)1922

return

data.substring(startindex 

+f.length, (index 

-startindex) 

-f.length);23}

下面是輸出測試

輸出1arraylist arrweather 

=qqweather();

2string

strweather 

=string

.empty;

3strweather 

+=arrweather[

0].tostring() +"

";4strweather +="

白天:+ arrweather[1].tostring() + "\

"border=0 /> ";

5strweather 

+=arrweather[

3].tostring() +"

";6strweather 

+=arrweather[

5].tostring() +"

";7strweather +="

夜晚:+ arrweather[2].tostring() + "\

"border=0 /> ";

8strweather 

+=arrweather[

4].tostring() +"

";9strweather 

+=arrweather[

6].tostring() +"

";10response.write(strweather);

下面是輸出效果截圖:

獲取天氣預報

接受查詢的城市 city get city 連線redis redis new redis redis connect 127.0.0.1 6379 選擇redis資料庫 redis select 1 獲取是否已經查詢過 生命週期為半小時 res redis get city 進行判斷 if emp...

android 獲取天氣預報

第一行 中獲取天氣的方法已經不行了,天氣老是不更新。搞了大半天,現在終於搞定了。一。資料 北京通過城市名字獲得天氣資料,json資料 通過城市id獲得天氣資料,json資料 獲得json的資料為 yesterday aqi 86 city 北京 按照道理,接下去應該比較容易了,只需要對json資料解...

VBS獲取天氣預報 BY Broly

vbs獲取天氣預報 code by broly 我的部落格 部分 參考網路 title 天氣預報 v1.0 by broly re.pattern u4e00 u9fa5 content 城市 city space 8 今天是 date vbcrlf vbcrlf content content 天...