Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # date: 2025.08.26
- # [pandas - Python 3.9, get in MS excel ALL physical addresses from the URL -> https://www.sappi.com/en-gb/about-us/locations - Stack Overflow](https://stackoverflow.com/questions/79746723/python-3-9-get-in-ms-excel-all-physical-addresses-from-the-url-https-www-s)
- # https://www.sappi.com/en-gb/about-us/locations
- from selenium import webdriver
- #import time
- # ---
- import selenium
- print('Selenium:', selenium.__version__)
- # ---
- url = "https://www.sappi.com/en-gb/about-us/locations"
- #driver = webdriver.Chrome()
- driver = webdriver.Firefox()
- driver.get(url)
- #time.sleep(5)
- html = driver.page_source
- driver.close()
- # ----
- from bs4 import BeautifulSoup
- import pandas as pd
- soup = BeautifulSoup(html, 'html.parser')
- location_cards = soup.find_all('article', class_='node-type__location')
- if len(location_cards) == 0:
- print("Can't find data !!!")
- else:
- data = []
- for card in location_cards:
- item = card.find('h3')
- name = item.get_text(strip=True, separator='|') if item else ""
- item = card.find('li', class_='location-address')
- address = item.get_text(strip=True, separator='|') if item else ""
- # there is no `location-country`
- #item = card.find('li', class_='location-country')
- item = card.find('span', class_='address-country')
- country = item.get_text(strip=True, separator='|') if item else ""
- data.append({
- 'Name': name,
- 'Address': address,
- 'Country': country
- })
- # Convert to DataFrame and export to Excel
- df = pd.DataFrame(data)
- df.to_excel('sappi_locations.xlsx', index=False)
- #df.to_csv('sappi_locations.csv', index=False)
- print("Data exported to sappi_locations.xlsx")
Advertisement