码迷,mamicode.com
首页 > 其他好文 > 详细

scrapy+email

时间:2020-02-08 22:05:42      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:url   email   sendmail   com   scrapy   ==   lib   smtplib   login   

import scrapy
import smtplib
from email.mime.text import MIMEText


class WeatherSpider(scrapy.Spider):
    name = "weather"
    start_urls = ["http://weather.com.cn/weather/101190502.shtml",]
    def parse(self,response):
        date = response.xpath("//div[@id=‘7d‘]/ul/li[1]/h1/text()").extract()
        data1 = response.xpath("//div[@id=‘7d‘]/ul/li[1]/p[@class=‘wea‘]/text()").extract()
        data2 = response.xpath("//div[@id=‘7d‘]/ul/li[1]/p[@class=‘tem‘]/span/text()").extract()
        data3 = response.xpath("//div[@id=‘7d‘]/ul/li[1]/p[@class=‘tem‘]/i/text()").extract()
        data4 = response.xpath("//div[@id=‘7d‘]/ul/li[1]/p[@class=‘win‘]/i/text()").extract()
        if data2 == []:
            lst =[今天:+date[0]+\n天气:+data1[0]+\n气温:+data3[0]+\n风力:+data4[0]]
        else:
            lst =[今天:+date[0]+\n天气:+data1[0]+\n气温:+data2[0]+~+data3[0]+\n风力:+data4[0]]
        
        
        #email部分有点小改动,原来的方法发不了
        user = 470811168@qq.com
        pwd = 
        to = 

        msg = MIMEText(‘‘.join(lst))
        msg[Subject] = Weather
        msg[From] = user
        msg[To] = to

        s = smtplib.SMTP()
        s.connect(smtp.qq.com,25)
        s.login(user,pwd)
        s.sendmail(user,to,msg.as_string())
        s.quit()

 

scrapy+email

标签:url   email   sendmail   com   scrapy   ==   lib   smtplib   login   

原文地址:https://www.cnblogs.com/puddingsmall/p/12285334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!