-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ddb8ff7
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from bs4 import BeautifulSoup | ||
import requests | ||
import string | ||
import streamlit | ||
|
||
input_data= input("search: ") | ||
u_i= string.capwords(input_data) | ||
lists= u_i.split() | ||
word= "_".join(lists) | ||
|
||
url= "https://en.wikipedia.org/wiki/"+word | ||
|
||
def wikifind(url): | ||
url_open= requests.get(url) | ||
soup= BeautifulSoup(url_open.content, "html.parser") | ||
details= soup('table', {'class': 'infobox'}) | ||
|
||
for i in details: | ||
h= i.find_all('tr') | ||
for j in h: | ||
heading= j.find_all('th') | ||
detail= j.find_all('td') | ||
if heading is not None and detail is not None: | ||
for x,y in zip(heading, detail): | ||
print("{} :: {}".format(x.text, y.text)) | ||
print("...................") | ||
|
||
for i in range(1,3): | ||
print(soup('p')[i].text) | ||
|
||
wikifind(url) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import streamlit as st | ||
import requests | ||
from bs4 import BeautifulSoup | ||
import string | ||
|
||
def get_wikipedia_data(keyword): | ||
url = "https://en.wikipedia.org/wiki/" + keyword | ||
response = requests.get(url) | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
infobox = soup.find('table', {'class': 'infobox'}) | ||
if infobox: | ||
details = {} | ||
rows = infobox.find_all('tr') | ||
for row in rows: | ||
heading = row.find('th') | ||
detail = row.find('td') | ||
if heading and detail: | ||
details[heading.text.strip()] = detail.text.strip() | ||
return details | ||
else: | ||
return None | ||
|
||
def main(): | ||
st.title("Know more about your word") | ||
input_data = st.text_input("Enter your word:") | ||
if input_data: | ||
keyword = "_".join(input_data.split()).capitalize() | ||
wiki_data = get_wikipedia_data(keyword) | ||
if wiki_data: | ||
st.write("### {}".format(keyword)) | ||
for key, value in wiki_data.items(): | ||
st.write("**{}:** {}".format(key, value)) | ||
else: | ||
st.write("No Wikipedia infobox found for {}".format(keyword)) | ||
|
||
if __name__ == "__main__": | ||
main() |