import requests, re from bs4 import BeautifulSoup 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 '] print("Please enter today's date:") while True: try: Month_in = int(input("Month (1-12): ").replace(' ', '')) except ValueError: print("Invalid input") continue if Month_in < 1: print("Insert a number greater than 0") continue elif Month_in > 12: print("Insert a number less than 13.") else: break if any(str(Month_in) in code for code in months_with_31_days): while True: try: Day = int(input("Day (1-31): ").replace(' ', '')) except ValueError: print("Invalid input") continue if Day < 1: print("Insert a number greater than 0") continue elif Day > 31: print("Insert a number less than 32.") else: break elif any(str(Month_in) in code for code in months_with_29_days): while True: try: Day = int(input("Day (1-29): ").replace(' ', '')) except ValueError: print("Invalid input") continue if Day < 1: print("Insert a number greater than 0") continue elif Day > 29: print("Insert a number less than 30.") else: break elif any(str(Month_in) in code for code in months_with_30_days): while True: try: Day = int(input("Day (1-30): ").replace(' ', '')) except ValueError: print("Invalid input") continue if Day < 1: print("Insert a number greater than 0") continue elif Day > 30: print("Insert a number less than 31.") 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 '] while True: try: Year = int(input("Year (yy): ").replace(' ', '')) except ValueError: print("Insert numberical value.") continue count = len(str(Year)) if count == 1: do = ['0', str(Year)] count = len(''.join(do)) if int(count) < 2: print("The year must contain two digits.") continue elif count > 2: print("The year must contain two digits.") else: break if len(str(Year)) < count: make = ['0', str(Year)] Year = ''.join(make) date = [str(Month[Month_in-1]), ' ', str(Day), ',', ' ', "20", str(Year)] final_date = ''.join(date) date_is = [final_date,' ', 'is'] date_is2 = ''.join(date_is) titles = '' messy_url = ['https://www.checkiday.com/', str(Month_in), '/', str(Day), '/', str(Year)] url = ''.join(messy_url) r = requests.get(url) soup = BeautifulSoup(r.content, 'lxml') links = soup.find_all('a') for l in links: title = l.get('title') titles = str(titles) + str(title) replace = {"None": "", "Tweet on Twitter": "", "Post on Facebook":"", "Checkiday.com":'', "Install us on Android":'', "!!":'!', '!':'\n', 'Like us on Facebook':'', 'Follow us on Twitter':'', 'Follow us on tumblr.':'', date_is2:''} replace = dict((re.escape(k), v) for k, v in replace.items()) pattern = re.compile("|".join(replace.keys())) titles = pattern.sub(lambda m: replace[re.escape(m.group(0))], titles) print(date_is2) print(titles)
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