This is a little python script to scrape the Dilbert of today and displays it.
To install dependencies, use $ pip install requests BeautifulSoup4 Pillow
Last active
May 31, 2020 03:59
-
-
Save DrBeta/3d1233510fde10da7a91dd55e8d78404 to your computer and use it in GitHub Desktop.
Dilbert.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import urllib.request | |
import time | |
from bs4 import BeautifulSoup | |
import io | |
import datetime | |
import urllib | |
from PIL import Image | |
def DilbertURL(dateToFetch): | |
formatted_date = '{0}-{1}-{2}'.format(dateToFetch.year, dateToFetch.month, dateToFetch.day) | |
todays_page = 'http://dilbert.com/strip/{0}/'.format(formatted_date) | |
response = requests.get(todays_page) | |
dilbert_page_source = BeautifulSoup(response.text, 'html.parser') | |
link = dilbert_page_source.find("img", class_='img-comic')['src'] | |
return "https:" + str(link) | |
print(DilbertURL(datetime.datetime.now())) | |
response = requests.get(DilbertURL(datetime.datetime.now())) | |
dilbert = Image.open(io.BytesIO(response.content)) | |
dilbert.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment