Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
from bs4 import BeautifulSoup
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def scrape_ttl():
|
| 7 |
+
url = 'https://eshop.ttl.com.tw/b2b_cpinfo.aspx?id=11530&catid=24'
|
| 8 |
+
response = requests.get(url)
|
| 9 |
+
response.encoding = 'utf-8'
|
| 10 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 11 |
+
|
| 12 |
+
# Extract the title
|
| 13 |
+
title = soup.find('span', id='packagename').text
|
| 14 |
+
|
| 15 |
+
# Extract the price
|
| 16 |
+
price = soup.find('span', id='price1', class_='price product-priceshow').text
|
| 17 |
+
|
| 18 |
+
# Create a DataFrame
|
| 19 |
+
data = {'Title': [title], 'Price': [price]}
|
| 20 |
+
df = pd.DataFrame(data)
|
| 21 |
+
|
| 22 |
+
return df
|
| 23 |
+
|
| 24 |
+
# Gradio interface
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=scrape_ttl,
|
| 27 |
+
inputs=[],
|
| 28 |
+
outputs="dataframe",
|
| 29 |
+
live=True,
|
| 30 |
+
title="TTL Product Scraper",
|
| 31 |
+
description="Scrape title and price of a TTL product."
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
iface.launch()
|