Apr-04-2018, 06:25 AM
Hello,
My current output:
What I want is table with clickable links, eg hyperlinks.
Example of what I want
Source of table: Here
My code:
My current output:
What I want is table with clickable links, eg hyperlinks.
Example of what I want
Source of table: Here
My code:
import csv import requests from bs4 import BeautifulSoup from tabulate import tabulate from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import smtplib me = 'MYEMAIL' password = 'MYPASSWORD' server = 'smtp.gmail.com:587' you = 'EMAILTOSEND' url="https://www.checkpoint.com/advisories/" r=requests.get(url) soup=BeautifulSoup(r.content,"lxml") table = soup.find('table') with open('a.csv', 'w+', newline='') as f: writer = csv.writer(f) for tr in table('tr'): row = [t.get_text(strip=True) for t in tr(['td', 'th'])] writer.writerow(row) html = """{table}""" with open('a.csv') as input_file: reader = csv.reader(input_file) data = list(reader) html = html.format(table=tabulate(data, headers="firstrow", tablefmt="html")) message = MIMEMultipart( "alternative", None, [MIMEText(html,'html')]) message['Subject'] = "Your data" message['From'] = me message['To'] = you server = smtplib.SMTP(server) server.ehlo() server.starttls() server.login(me, password) server.sendmail(me, you, message.as_string()) server.quit()