import requests from bs4 import BeautifulSoup print("Please enter your birthday:") while True: try: BD_Month = int(input("Month (1-12): ").replace(' ', '')) except ValueError: print("Invalid input") continue if BD_Month < 1: print("Insert a number greater than 0") continue elif BD_Month > 12: print("Insert a number less than 13.") else: break Months = ('january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december') Month = dict(zip(range(12), Months)) months_with_30_days = ['9', '4', '6', '11'] months_with_31_days = ['1', '3', '5 ', '7', '8', '10', '12'] months_with_29_days = ['2 '] if any(str(BD_Month) in code for code in months_with_31_days): while True: try: BD_Day = int(input("Day (1-31): ").replace(' ', '')) except ValueError: print("Invalid input") continue if BD_Day < 1: print("Insert a number greater than 0") continue elif BD_Day > 31: print("Insert a number less than 32.") else: break elif any(str(BD_Month) in code for code in months_with_29_days): while True: try: BD_Day = int(input("Day (1-29): ").replace(' ', '')) except ValueError: print("Invalid input") continue if BD_Day < 1: print("Insert a number greater than 0") continue elif BD_Day > 29: print("Insert a number less than 30.") else: break elif any(str(BD_Month) in code for code in months_with_30_days): while True: try: BD_Day = int(input("Day (1-30): ").replace(' ', '')) except ValueError: print("Invalid input") continue if BD_Day < 1: print("Insert a number greater than 0") continue elif BD_Day > 30: print("Insert a number less than 31.") else: break messy_url = ['http://www.famousbirthdays.com/', str(Month[BD_Month - 1]), str(BD_Day), '.html'] url = ''.join(messy_url) #Need completed url to be scraped r = requests.get(url) soup = BeautifulSoup(r.content, 'lxml') spans = soup.find_all('span', attrs={'class':'title'}) print("The following people were born on your birthday:") for span in spans: print(span.string)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question