selector = etree.HTML(html.text)
china_list = selector.xpath(“//*[@id=‘table1’]/div[4]/div”)
china_result = {}
china_detail = []
for province in china_list:
province_name = (province.xpath(“div[1]/div[1]/text()”)[0])
province_confirm = int((province.xpath(“div[1]/div[2]/text()”)[0]))
province_died = int((province.xpath(“div[1]/div[3]/text()”)[0]))
province_cure = int((province.xpath(“div[1]/div[3]/text()”)[0]))
province_city = province.xpath(“div[2]/div”)
province_city_result = []
for city in province_city:
city_name = city.xpath(“div[1]/text()”)[0]
city_confirm = int(city.xpath(“div[2]/text()”)[0])
city_died = int(city.xpath(“div[3]/text()”)[0])
city_cure = int(city.xpath(“div[4]/text()”)[0])
province_city_result.append({
“城市名”: city_name,
“确诊数”: city_confirm,
“死亡数”: city_died,
“治愈数”: city_cure
})
item = {
“省份名”: province_name,
“确诊数”: province_confirm,
“死亡数”: province_died,
“治愈数”: province_cure,
“下属城市”: province_city_result
}
china_detail.append(item)
china_result[“详细数据”] = china_detail
china_today_confirm = int(selector.xpath(“/html/body/div[1]/div[3]/div[1]/div[2]/div/div[1]/p[1]/text()”)[0])
china_today_suspect = int(selector.xpath(“/html/body/div[1]/div[3]/div[1]/div[2]/div/div[2]/p[1]/text()”)[0])
china_today_cure = int(selector.xpath(“/html/body/div[1]/div[3]/div[1]/div[2]/div/div[3]/p[1]/text()”)[0])
china_today_death = int(selector.xpath(“/html/body/div[1]/div[3]/div[1]/div[2]/div/div[4]/p[1]/text()”)[0])
china_total_confirm = int(selector.xpath(“/html/body/div[1]/div[3]/div[2]/div[2]/div/div[1]/p[1]/text()”)[0])
china_total_suspect = int(selector.xpath(“/html/body/div[1]/div[3]/div[1]/div[2]/div/div[2]/p[1]/text()”)[0])
china_total_cure = int(selector.xpath(“/html/body/div[1]/div[3]/div[1]/div[2]/div/div[3]/p[1]/text()”)[0])
china_total_death = int(selector.xpath(“/html/body/div[1]/div[3]/div[1]/div[2]/div/div[4]/p[1]/text()”)[0])
china_result[“今日数据”] = {“新增确诊”: china_today_confirm, “新增疑似”: china_today_suspect, “新增治愈”: china_today_cure,
“新增死亡”: china_today_death, }
china_result[“累计病例”] = {“确诊病例”: china_total_confirm, “疑似病例”: china_total_suspect, “治愈病例”: china_total_cure,
“死亡病例”: china_total_death, }
world_list = selector.xpath(“//*[@id=‘table2’]/div[4]/div/div/div”)
world_result = {}
world_detail = []
for country in world_list:
country_name = (country.xpath(“div[1]/text()”)[0])
country_confirm = (country.xpath(“div[2]/text()”)[0])
country_cure = (country.xpath(“div[3]/text()”)[0])
country_death = (country.xpath(“div[4]/text()”)[0])
item = {
“国家名”: country_name,
“确诊数”: country_confirm,
“死亡数”: country_cure,
“治愈数”: country_death
}
world_detail.append(item)
world_result[“详细数据”] = world_detail
world_today_confirm = int(selector.xpath(“/html/body/div[1]/div[4]/div[1]/div[2]/div/div[1]/p[1]/text()”)[0])
感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的:
① 2000多本Python电子书(主流和经典的书籍应该都有了)
② Python标准库资料(最全中文版)
③ 项目源码(四五十个有趣且经典的练手项目及源码)
④ Python基础入门、爬虫、web开发、大数据分析方面的视频(适合小白学习)
⑤ Python学习路线图(告别不入流的学习)
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!