From Baidu weather to get the local weather conditions tomorrow, if it rains tomorrow, please send an e-mail to inform all colleagues with umbrellas,
If the temperature is below 10 degrees tomorrow, please email to remind colleagues to keep warm, if the temperature is above 30, remind colleagues to pay attention to high temperature.
Suppose there is a way to send mail Self.send_email (email_content)
The code is as follows:
#coding =utf-8from selenium import webdriverimport unittestfrom time import Sleepclass weatherreport (unittest. TestCase): def setup (self): self.dr = webdriver. Chrome () self.weather, self.the_highest_temperature, Self.the_lowest_temperatrue = self.get_tomorrow_weather_and_temperature () self.content = self.email_content () def get_ Tomorrow_weather_and_temperature (self): self.baidu_search (' Chengdu weather ') sleep (5) Weather = self.dr.find_elements_by_css_selector ('. Op_weather4_twoicon_weath ') [1].text #首先获取明日天气 print (' Tomorrow's weather is%s ' %weather) temperature = self.dr.find_elements_by_css_ Selector ('. Op_weather4_twoicon_temp ') [1].text #其次获取明日温度 The_highest_temperature = int (Temperature.split (' ~ ') [0]) #从温度中获取明日最高温度并转为整型 print (' Tomorrow's highest temperature%s℃ ' %the_highest_temperature) the_lowest_temperature = temperature.split (' ~ ') [1] # Get tomorrow's lowest temperature from the temperature print (' Tomorrow's lowest temperature%s ' %the_lowest_temperature) return weather, the_highest_temperature, the_ Lowest_temperature def baidu_search (Self, cityweather): self.dr.get (' http://www.baidu.com ') self.dr.find_element_by_ID (' kw '). Send_keys (Cityweather) self.dr.find_element_by_id (' su ') ). Click () def email_content (self): if ' Rain ' in self.weather: content = ' Notice: Tomorrow there is rain, please all colleagues with umbrellas! ' else: if self.the_highest_temperature > 30: content = ' Reminder: Tomorrow the temperature is above 30 degrees, please pay attention to all colleagues high temperature ' elif self.the_highest_temperature < 10: content = ' Reminder: Tomorrow the temperature is below 10 degrees, please all colleagues attention warmth ' else: content = ' return Content def test_send_email (self): Print ('%s ' %self.content) def teardown (self): self.dr.quit () if __name__ == ' __main__ ': unittest.main ()
The page is as follows:
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://images2015.cnblogs.com/blog/942023/201612/942023-20161222161834401-740071924.png "style=" border:0px; Font-family:verdana, Arial, Helvetica, Sans-serif;font-size:14px;line-height:21px;white-space:normal; Background-color:rgb (255,255,255); "/>
The results are as follows:
650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/942023/201612/942023-20161222161915495-1771224010. PNG "style=" Border:0px;font-family:verdana, Arial, Helvetica, sans-serif;font-size:14px;line-height:21px; White-space:normal;background-color:rgb (255,255,255); "/>
This article comes from "No idea, no achievement!" "Blog, be sure to keep this provenance http://kemixing.blog.51cto.com/10774787/1885132
Use Python+selenium from Baidu to get local weather information for tomorrow and according to the temperature of the mail alert