python 3.6 urllib庫實現天氣爬取、郵件定時給妹子發送天氣 【ongoing】,urllibongoing
#由於每天早上要和妹子說早安,報告天氣情況。。所以就想能不能做個定時任務,每天早上自動爬取天氣,發送早安郵件~23333
#靠譜小測試一枚,代碼歡迎吐槽,共同進步;
#
#涉及模組:
#(1)定時任務:由於是小工具,不至於買台伺服器(其實是沒錢),手上只有一台11年上大學的win7,就配了個windows的定時任務
# 配置教程連結:http://blog.csdn.net/wwy11/article/details/51100432
#(2)爬取天氣:用的是中國天氣網-http://www.weather.com.cn/weather/101190101.shtml 101190101為城市id,動態擷取
# 爬蟲代碼見上一篇部落格-http://www.cnblogs.com/yuebai/p/6728532.html
#(3)發送郵件:代碼同在上一篇部落格
#(4)結束處理:os.system('shutdown -s -t 1')
# -*- coding: utf-8 -*-import sysfrom learn.crawler_learn import tools_my_crawlercity_code_dic = { "南京":"101190101", "北京":"101010100" }class MORNING(tools_my_crawler.CRAWLER): def get_wertherUrl_by_cityName(self,cityName): cityId = city_code_dic[cityName] if cityId == "": print("get cityId failed,plz check %s is not in city_code_dic"%cityName) sys.exit(1) else: wertherUrl = "http://www.weather.com.cn/weather/" + cityId + ".shtml" #print(wertherUrl) return wertherUrl def main(): ZMJ = MORNING() weatherUrl = ZMJ.get_wertherUrl_by_cityName("南京") print("01 weatherUrl =",weatherUrl) flag_today = '<li class="sky skyid lv3 on">' # items_today = ZMJ.select_items_from_url(weatherUrl,) main()