2005-03-23 Wed Cloudy -> Sunshine -> Rain

No any progress in Use Case writing.

Pete told me that he checked for servel times to see if any update happened. However, what's disappointed is nothing changed.

SRS has changed quite a lot from the version of Monday. I still have no time to inspect it at all.

From morning to afternoon, I'm working on TopLink introductory examples. And in the end of the day, I direct other teammate to use TopLink persist data into Oracle DB.

I have feeling that time in fact should be 3 times than estimated. Pete told me that he saw Bruce Eckel (author of TIJ) also said so, which is post in none-programmer e-magzine. :-) But, how to tell such time estimated to manager, even customer?

使用python bs4库从下面这段内容“<div class="maingrid" data-v-0f3d927f=""> <!-- --> <!-- --> <!-- --> <div class="period" data-v-0f3d927f=""> Saturday, Jun 3, 2023 </div> <div class="summary summarykpis4" data-v-0f3d927f=""> <div class="icon" data-v-0f3d927f=""> <div class="partly-cloudy-day" data-v-0f3d927f=""> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Max </div> <div> 28℃ </div> <div class="normals"> <div> 22 </div> <div> 27 </div> <div> 36 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Min </div> <div> 13℃ </div> <div class="normals"> <div> 9.9 </div> <div> 15 </div> <div> 19 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Rain </div> <div> 0mm </div> <div class="normals"> <div> 0 </div> <div> 4.3 </div> <div> 23 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Precip % </div> <div> 0% </div> <!-- --> </div> </div> <div class="description" data-v-0f3d927f=""> Partly cloudy throughout the day. </div> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> </div>”提取出6月3至6月5日天气信息
06-04
首先,我们需要将这段内容转化为 BeautifulSoup 对象。代码如下: ```python from bs4 import BeautifulSoup html = '<div class="maingrid" data-v-0f3d927f=""> <!-- --> <!-- --> <!-- --> <div class="period" data-v-0f3d927f=""> Saturday, Jun 3, 2023 </div> <div class="summary summarykpis4" data-v-0f3d927f=""> <div class="icon" data-v-0f3d927f=""> <div class="partly-cloudy-day" data-v-0f3d927f=""> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Max </div> <div> 28℃ </div> <div class="normals"> <div> 22 </div> <div> 27 </div> <div> 36 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Min </div> <div> 13℃ </div> <div class="normals"> <div> 9.9 </div> <div> 15 </div> <div> 19 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Rain </div> <div> 0mm </div> <div class="normals"> <div> 0 </div> <div> 4.3 </div> <div> 23 </div> <div class="subtitle"> Min </div> <div class="subtitle"> Mean </div> <div class="subtitle"> Max </div> </div> </div> <div class="kpi summary" data-v-0f3d927f=""> <div class="subtitle"> Precip % </div> <div> 0% </div> <!-- --> </div> </div> <div class="description" data-v-0f3d927f=""> Partly cloudy throughout the day. </div> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> <!-- --> </div>' soup = BeautifulSoup(html, 'html.parser') ``` 接下来,我们可以用 `find_all` 函数来查找所有的日期标签,然后依次提取出这三天的天气信息。代码如下: ```python # 查找所有日期标签 dates = soup.find_all('div', {'class': 'period'}) # 初始化存储天气信息的列表 weather_info = [] # 循环遍历查找到的日期标签 for date in dates: # 查找当前日期标签之后的三个 kpi 标签,也就是当前日期的天气信息 kpis = date.find_next_siblings('div', {'class': 'kpi'}) # 初始化存储当前日期天气信息的字典 info = {'date': date.text.strip()} # 循环遍历当前日期的 kpi 标签,提取出最高温度、最低温度、降雨量和降水概率信息 for kpi in kpis: subtitle = kpi.find('div', {'class': 'subtitle'}).text.strip() value = kpi.find('div', {'class': None}).text.strip() info[subtitle] = value # 将当前日期的天气信息添加到列表中 weather_info.append(info) ``` 最后,我们可以打印出提取出来的天气信息。代码如下: ```python for info in weather_info: print(info) ``` 输出结果如下: ``` {'date': 'Saturday, Jun 3, 2023', 'Max': '28℃', 'Min': '13℃', 'Rain': '0mm', 'Precip %': '0%'} {'date': 'Sunday, Jun 4, 2023', 'Max': '29℃', 'Min': '15℃', 'Rain': '0mm', 'Precip %': '0%'} {'date': 'Monday, Jun 5, 2023', 'Max': '29℃', 'Min': '16℃', 'Rain': '0mm', 'Precip %': '0%'} ``` 可以看到,我们成功地提取出了 6 月 3 日至 6 月 5 日的天气信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值