Python Forum
How to get hyperlinks in to the table extracted by BeautifulSoup
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get hyperlinks in to the table extracted by BeautifulSoup
#1
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()
Reply
#2
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
Reply
#3
This is the sense of a forum.
The people who are seeking solutions, find posts in forums.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beautifulsoup table question tantony 5 2,796 Sep-30-2019, 03:26 PM
Last Post: tantony
  BeautifulSoup: Error while extracting a value from an HTML table kawasso 3 3,218 Aug-25-2019, 01:13 AM
Last Post: kawasso
  BeautifulSoup - extract table but not using ID jonesin1974 5 29,126 Apr-27-2018, 07:22 PM
Last Post: NinoBaus
  Read input file and print hyperlinks Emmanouil 8 15,194 Oct-23-2016, 07:26 PM
Last Post: snippsat
  BeautifulSoup - Table tkj80 6 9,757 Oct-21-2016, 01:23 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020