[Python] Extracting table from UPS website using BeautifulSoup [closed]

Discussão em 'Python' iniciado por Stack, Novembro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to extract the US diesel price surcharge by table id using the below code, and it's only reading until <thead> but not <tbody>. What am I doing wrong?

    url = 'https://www.ups.com/us/en/shipping/surcharges/fuel-surcharges.page'
    response = requests.get(url)
    print(response.status_code)
    soup = BeautifulSoup(response.content,"html.parser")
    tables = soup.find(id="USDiesel")
    print(tables)
    tables_all = []
    for tr in tables.find_all('tr'):
    data = []
    for td in tr.find_all('td'):
    data.append(td.text.strip())
    tables_all.append(data)
    table_df = pd.DataFrame(tables_all)
    headers = table_df.iloc[0]
    UPS_Gfuelsurcharge_df = pd.DataFrame(table_df.values[1:], columns=headers)
    print(UPS_Gfuelsurcharge_df)

    Continue reading...

Compartilhe esta Página