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}")
2
Answers
Can you check this out if this is what you are looking for?
I used their
page-data
(JSON) endpoint to grab all these addresses.Let me know if I missed something based on your question
All the information you need can be found here which means that you only have to parse a JSON document to get the required results.
Output: