-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWikipeda Article Code.py
More file actions
38 lines (30 loc) · 1.12 KB
/
Copy pathWikipeda Article Code.py
File metadata and controls
38 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import requests
from bs4 import BeautifulSoup
import webbrowser
usr_title = input("What kind of article do you want on Wikipedia?: ").strip()
while True:
main_url = "https://en.wikipedia.org/wiki/{}".format(usr_title)
get = requests.get(main_url)
soup = BeautifulSoup(get.content, 'html.parser')
title = soup.find(class_ = "firstHeading").text
print(title + "\nDo You want to view it? (Y/N/T -to exit)")
ans = str(input(""))
if (ans.lower() == "y"):
url = 'https://en.wikipedia.org/wiki/%s' %title
webbrowser.open(url)
break
elif (ans.lower() == "n"):
print("ok\nEnter a different article name!")
usr_title = input("What kind of article do you want on Wikipedia?: ").strip()
continue
elif (ans.lower() == "t"):
break
else:
print("Bad Input!")
ans = str(input("Do you want to try again? (Y/N) "))
if (ans.lower() == "y"):
usr_title = input("Enter something more specific:").strip()
continue
elif( ans.lower() == "n"):
print("Terminating the program.")
break