#!/root/.pyenv/shims/python#-*- coding: UTF-8 -*-importsysimporttimeimportrequestsfrombs4importBeautifulSoupimportsmtplibfromemail.mime.multipartimportMIMEMultipartfromemail.mime.textimportMIMEText#Some User Agentshds=[{'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'}]defsend_email(weather_info_html):# setup to listtolist=['TO ADDR 1','TO ADDR 2']# login fromaddr="YOUR GOOGLE EMAIL ADDR"fromaddr_pw="PASSWORD"server=smtplib.SMTP('smtp.gmail.com',587)server.starttls()server.login(fromaddr,fromaddr_pw)# make up and send the msgmsg=MIMEMultipart()msg['Subject']="Weather Mail"+"["+time.strftime("%a, %d %b",time.gmtime())+"]"msg['From']=fromaddrmsg['To']=", ".join(tolist)msg.attach(MIMEText(weather_info_html,'html'))# plain will send plain textserver.sendmail(fromaddr,tolist,msg.as_string())# logoutserver.quit()defweather_notice():url='http://www.tenki.jp/world/5/90/54511.html'# beijing, Chinatry:html=requests.get(url,headers=hds[0],allow_redirects=False,timeout=3)ifhtml.status_code==200:soup=BeautifulSoup(html.text.encode(html.encoding),"html.parser")town_info_block=soup.find('div',{'id':'map_world_point_wrap'})town_info_block=str(town_info_block)exceptExceptionase:print(url,e,str(time.ctime()))if__name__=="__main__":weather_notice()