Skip to content

Instantly share code, notes, and snippets.

@Ch3mjor
Last active June 7, 2019 09:48
Show Gist options
  • Save Ch3mjor/46b9e6eff51f09d64f6a11ca5aac004a to your computer and use it in GitHub Desktop.
Save Ch3mjor/46b9e6eff51f09d64f6a11ca5aac004a to your computer and use it in GitHub Desktop.
A python script to get jokes from icanhazdadjoke.com
#Code to scrape https://icanhazdadjoke.com/
#It will generate one joke from terminal
#You need to install the following modules: requests, bs4, pyfiglet and termcolor (You can use pip)
import requests
from bs4 import BeautifulSoup
from random import choice
from pyfiglet import figlet_format
from termcolor import colored
value = ""
#Why 3000? It's the coolest number!
header = figlet_format("KIPLIMO JOKEs 3000!")
header = colored(header, color = "magenta")
print(header)
while value != "n":
#Url to obtain jokes
url ="https://icanhazdadjoke.com/"
response= requests.get(url)
html = response.content
#Passing data into BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
joke_body= (soup.select(".subtitle")[1])
joke = joke_body.get_text()
joke = colored(joke, color = "blue")
print(joke)
print("\n" * 5)
value = input("Would you like another joke?(y/n)")
print("\n" * 2)
@Ch3mjor
Copy link
Author

Ch3mjor commented Jun 7, 2019

This will print out a joke on your terminal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment