Python Forum

Full Version: How to get hyperlinks in to the table extracted by BeautifulSoup
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

My current output: [Image: vcHrG7h]
What I want is table with clickable links, eg hyperlinks.
Example of what I want[Image: doc-list-create-hyperlinks-6.png]
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()
Uhmm,

I fixed it by removing strip on line 23...

But I can't find a delete button on my thread

[Image: hmn6ONl.png]

Admin, could you help? XD srysry
This is the sense of a forum.
The people who are seeking solutions, find posts in forums.