Last active
June 7, 2019 09:48
-
-
Save Ch3mjor/46b9e6eff51f09d64f6a11ca5aac004a to your computer and use it in GitHub Desktop.
A python script to get jokes from icanhazdadjoke.com
This file contains 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
#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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will print out a joke on your terminal.