Spaces:
Build error
Build error
| import requests | |
| from bs4 import BeautifulSoup | |
| import pandas as pd | |
| import gradio as gr | |
| def scrape_ttl(): | |
| url = 'https://eshop.ttl.com.tw/b2b_cpinfo.aspx?id=11530&catid=24' | |
| response = requests.get(url) | |
| response.encoding = 'utf-8' | |
| soup = BeautifulSoup(response.text, 'html.parser') | |
| # Extract the title | |
| title = soup.find('span', id='packagename').text | |
| # Extract the price | |
| price = soup.find('span', id='price1', class_='price product-priceshow').text | |
| # Create a DataFrame | |
| data = {'Title': [title], 'Price': [price]} | |
| df = pd.DataFrame(data) | |
| return df | |
| # Gradio interface | |
| iface = gr.Interface( | |
| fn=scrape_ttl, | |
| inputs=[], | |
| outputs="dataframe", | |
| live=True, | |
| title="TTL Product Scraper", | |
| description="Scrape title and price of a TTL product." | |
| ) | |
| iface.launch() | |