October 22, 2024
Chicago 12, Melborne City, USA
python

Using Python 3.9, How do I get in MS excel ALL physical addresses from the URL -> https://www.tamoil.ch/en/store-locator


I would like to get all physical addresses in MS-excel from this url [https://www.tamoil.ch/en/store-locator]. The spreadsheet only has a header, but no output from the code.

import requests
from bs4 import BeautifulSoup
import pandas as pd

# Send a GET request to the website
url = "https://www.tamoil.ch/en/store-locator"

response = requests.get(url)

# Parse the HTML content
soup = BeautifulSoup(response.content, 'html.parser')

# Find all elements containing store information
store_elements = soup.find_all('div', class_='store-element')

# Extract addresses
addresses = []
for store in store_elements:
    address = store.find('p', class_='address').text.strip()
    addresses.append(address)

# Create a DataFrame
df = pd.DataFrame({'Address': addresses})

# Save to Excel file
excel_file="tamoil_addresses.xlsx"
df.to_excel(excel_file, index=False)

print(f"Addresses saved to {excel_file}")



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video