| import streamlit as st |
| import requests |
| from bs4 import BeautifulSoup |
| from PIL import Image |
| from io import BytesIO |
|
|
| |
| def get_html(url): |
| response = requests.get(url) |
| return response.text |
|
|
| |
| def parse_page(html): |
| soup = BeautifulSoup(html, 'html.parser') |
| return soup |
|
|
| |
| def main(): |
| st.title('Информация с сайта Superetka') |
|
|
| |
| url = 'https://superetka.com/etka/wap.php' |
|
|
| |
| html = get_html(url) |
|
|
| |
| soup = parse_page(html) |
|
|
| |
| headings = soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']) |
|
|
| |
| for heading in headings: |
| st.header(heading.text.strip()) |
|
|
| |
| if heading.find_next('img'): |
| img_url = heading.find_next('img')['src'] |
| img_response = requests.get(img_url) |
| img = Image.open(BytesIO(img_response.content)) |
| st.image(img, caption='Изображение') |
|
|
| |
| content = heading.find_next_sibling() |
| if content: |
| st.markdown(content.text.strip(), unsafe_allow_html=True) |
|
|
| st.write('---') |
|
|
| |
| if __name__ == '__main__': |
| main() |
|
|