Spaces:
Runtime error
Runtime error
Create backup-app.py
Browse files- backup-app.py +46 -0
backup-app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
import streamlit as st
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
urls = ['https://en.wikipedia.org/wiki/Health_care',
|
| 7 |
+
'https://en.wikipedia.org/wiki/Health_information_on_the_Internet',
|
| 8 |
+
'https://www.who.int/health-topics/coronavirus#tab=tab_1']
|
| 9 |
+
|
| 10 |
+
def scrape_wikipedia(url):
|
| 11 |
+
try:
|
| 12 |
+
start_time = time.time()
|
| 13 |
+
response = requests.get(url)
|
| 14 |
+
end_time = time.time()
|
| 15 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
| 16 |
+
div_element = soup.find('div', {'class': 'div-col columns column-width'})
|
| 17 |
+
if div_element is not None:
|
| 18 |
+
articles_list = div_element.find_all('li')
|
| 19 |
+
else:
|
| 20 |
+
articles_list = []
|
| 21 |
+
return {'url': url, 'response_time': end_time - start_time, 'response': response, 'articles': articles_list}
|
| 22 |
+
except:
|
| 23 |
+
return {'url': url, 'response_time': None, 'response': None, 'articles': []}
|
| 24 |
+
|
| 25 |
+
def main():
|
| 26 |
+
st.title("List of Articles on Health Care")
|
| 27 |
+
|
| 28 |
+
data = []
|
| 29 |
+
for url in urls:
|
| 30 |
+
st.write(f"Scraping {url}...")
|
| 31 |
+
scraped_data = scrape_wikipedia(url)
|
| 32 |
+
st.write(f"Response time: {scraped_data['response_time']}")
|
| 33 |
+
st.write(scraped_data['response'])
|
| 34 |
+
for article in scraped_data['articles']:
|
| 35 |
+
data.append({'url': scraped_data['url'], 'article': article.text})
|
| 36 |
+
|
| 37 |
+
st.write('## Dataset')
|
| 38 |
+
st.dataframe(data)
|
| 39 |
+
|
| 40 |
+
st.write('## Grid')
|
| 41 |
+
st.write('url', 'article')
|
| 42 |
+
for d in data:
|
| 43 |
+
st.write(d['url'], d['article'])
|
| 44 |
+
|
| 45 |
+
if __name__ == '__main__':
|
| 46 |
+
main()
|