如何使用python从csv文件发送电子邮件?

时间:2019-02-25 12:34:52

标签: python-2.7 csv email web-scraping

我正在将数据从网站抓取到csv。我想通过电子邮件发送这些信息,不带附件,仅发送数据。 (以表格格式,具有很好的阅读格式。)

这是我的代码:

            my_url = requests.get('https://www.telekom.hu/shop/categoryresults/?N=10994&contractType=list_price&instock_products=1&Ns=sku.sortingPrice%7C0%7C%7Cproduct.displayName%7C0&No=0&Nrpp=9&paymentType=FULL')
        data = my_url.json()
        results = []
        products = data['MainContent'][0]['contents'][0]['productList']['products']
        for product in products:
                name = product['productModel']['displayName']
            try:
                priceGross = product['priceInfo']['priceItemSale']['gross']
            except:
                priceGross = product['priceInfo']['priceItemToBase']['gross']
                url = telekom+product['productModel']['url']

                results.append([name, priceGross, url])
        df = pd.DataFrame(results, columns = ['Name', 'Price', 'Url'])    
        print df
        print(df)
        df.to_csv(r'/usr/src/Python-2.7.13/test.csv', sep=',', encoding='utf-8',index = False )


            server = smtplib.SMTP('smtp.gmail.com', 587)
            server.starttls()
            server.login("login informations)

            msg = "some text and after this i need the csv table"
            server.sendmail("MYEMAIL", "email@email.hu", msg)
            server.quit() 

0 个答案:

没有答案