Selenium学习笔记||五、练习(天气网查最低温度)
from selenium import webdriver driver = webdriver.Chrome(r"D:\webdriver\chromedriver_73.0.3683.68.exe") driver.get("http://www.weather.com.cn/html/province/jiangsu.shtml") eles = driver.find_element_by_id("forecastID") citys = eles.text.split('℃\n') lowest_temp = None lowest_city = [] for city in citys: city_name = city.split('\n')[0] city_temp = city.split('\n')[1].replace("℃", "").split('/') city_low = int(city_temp[1]) if lowest_temp == None or city_low < lowest_temp: lowest_temp = city_low lowest_city = [city_name] elif lowest_temp == city_low: lowest_city.append(city_name) print("全省最低温度为:{},出现在{}。".format(lowest_temp,'/'.join(lowest_city))) driver.quit()
要求:
http://www.weather.com.cn/html/province/jiangsu.shtml获取江苏所有城市的天气,并找出其中每天最低气温最低的城市,显示出来,比如 温度最低为12℃, 城市有连云港 盐城