Skip to content

Instantly share code, notes, and snippets.

@devster31
Created November 5, 2020 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devster31/e8960c36099e440f0a652488decdac2f to your computer and use it in GitHub Desktop.
Save devster31/e8960c36099e440f0a652488decdac2f to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
css = """
table {
color: #666;
font-family: 'Raleway', sans-serif;
font-size: 16px;
font-weight: 400;
box-sizing: border-box;
border-collapse: collapse;
border-spacing: 0;
line-height: 2;
margin-bottom: 40px;
width: 100%;
}
tbody {
color: #666;
font-family: 'Raleway', sans-serif;
font-size: 16px;
font-weight: 400;
border-collapse: collapse;
border-spacing: 0;
line-height: 2;
box-sizing: border-box;
border-bottom: 1px solid #ddd;
}
tr {
color: #666;
font-family: 'Raleway', sans-serif;
font-size: 16px;
font-weight: 400;
border-collapse: collapse;
border-spacing: 0;
line-height: 2;
box-sizing: border-box;
}
td {
color: #666;
font-family: 'Raleway', sans-serif;
font-size: 16px;
font-weight: 400;
border-collapse: collapse;
border-spacing: 0;
line-height: 2;
width: 105px;
box-sizing: border-box;
text-align: left;
border-top: 1px solid #ddd;
padding: 6px 0;
}
h2 {
font-family: 'Raleway', sans-serif;
box-sizing: border-box;
color: #000;
font-weight: 700;
line-height: 1.2;
margin: 0 0 16px;
font-size: 30px;
}
h3 {
font-family: 'Raleway', sans-serif;
box-sizing: border-box;
color: #000;
font-weight: 700;
line-height: 1.2;
margin: 0 0 16px;
font-size: 24px;
}
p {
color: #666;
font-family: 'Raleway', sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 1.625;
box-sizing: border-box;
margin: 0 0 24px;
padding: 0;
margin-bottom: 26px;
}
ul {
color: #666;
font-family: 'Raleway', sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 1.625;
box-sizing: border-box;
margin: 0;
padding: 0;
margin-bottom: 26px;
margin-left: 40px;
}
li {
color: #666;
font-family: 'Raleway', sans-serif;
font-size: 16px;
font-weight: 400;
line-height: 1.625;
box-sizing: border-box;
list-style-type: disc;
}
"""
page = requests.get("https://www.antibodysociety.org/covid-19-biologics-tracker/")
soup = BeautifulSoup(page.content, "lxml")
table = soup.find("table")
title = table.find_previous_sibling("h2")
highlights = table.find_next_siblings(["h3", "p", "ul"])
document = BeautifulSoup("<head><style>{}</style></head>".format(css), features="lxml")
document.html.append(title)
document.html.append(table)
document.html.extend(highlights)
res = requests.post(
"https://api.mailgun.net/v3/THE_DOMAIN/messages",
auth=("api", "THE_API_TOKEN"),
data={
"from": '"Grande Capo" <estiquaatsi@noreply.com>',
"to": [
"recipient1@mail.com",
"recipient2@mail.com",
],
"subject": "testing",
"html": document.html.prettify(),
},
)
print(res, res.text)
beautifulsoup4~=4.9.3
lxml~=4.6.1
requests~=2.24.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment