[英]How to make a good visualization in a table?
下面的代碼創建了一個新聞表,並通過郵件將其發送給收件人。 output(郵件中的表格)看起來很糟糕,所以它不是設計的,並且有一列顯示行數。
有沒有可能刪掉這一欄,把桌子設計得更漂亮一點,像藍白條紋的桌子?
import csv, ssl
import smtplib
from GoogleNews import GoogleNews
ssl._create_default_https_context = ssl._create_unverified_context
googlenews = GoogleNews()
googlenews.set_encode('utf_8')
googlenews.set_lang('en')
googlenews.set_period('7d')
googlenews.get_news("New York")
keys = googlenews.results()[0].keys()
table = []
for row in googlenews.results():
table.append({'Titel': row['title'], 'Datum': row['date'], 'URL': row['link'],
'Quelle': row['site']})
import cred
import pandas as pd
from email.message import EmailMessage
df = pd.DataFrame(table)
from_mail = "example@gmail.com"
from_password = cred.passwort
to_mail = ['example@hotmail.com']
smtp_server = "smtp.gmail.com"
smtp_port = 465
def send_email(smtp_server, smtp_port, from_mail, from_password, to_mail):
'''
Send results via mail
'''
msg = EmailMessage()
msg['Subject'] = 'News'
msg['From'] = from_mail
msg['To'] = ', '.join(to_mail + [from_mail])
html = """\
<html>
<head></head>
<body>
{0}
</body>
</html>
""".format(df.to_html())
msg.set_content(html, 'html')
with smtplib.SMTP_SSL(smtp_server, smtp_port) as server:
server.ehlo()
server.login(from_mail, from_password)
server.send_message(msg)
server.quit()
send_email(smtp_server, smtp_port, from_mail, from_password, to_mail)
使 HTML 更好看的一種方法是 CSS。 CSS 是一種用於造型 HTML 的語言。 它可用於調整添加 colors、邊框、輪廓等到 HTML。 您可以使用<style>
標記在<head>
部分中添加全局 CSS,或將其應用於具有style
屬性的單個標記。
如果你想了解 CSS,我會推薦W3 學校的CSS 教程。
我知道這不是復制和粘貼的答案,但我本人不是 CSS 的專家。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.