File size: 842 Bytes
ef7e6b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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()