Scrape Coordinates with Beautiful Soup

``` python 3

from bs4 import BeautifulSoup
import pandas as pd
#open downloaded html, adjust encoding
with open("webpage.html", encoding='utf-8') as fp:
soup = BeautifulSoup(fp, features="html.parser")
#create empty lists for desired data
names = []
addresses = []
latitude = []
longitude = []
#loop through document
#fist argument in find_all is the name of element, then attributes
#for each card, get desired data and push into relateed list
for div in soup.find_all("div", class_="card-component place-card"):
    names.append(div.get('data-name'))
    addresses.append(div.get('data-address'))
    latitude.append(div.get('data-latitude'))
    longitude.append(div.get('data-longitude')
#create panda dataframe based on python lists, then translate into csv
df = pd.DataFrame({'Pharmacies':names,'Location':addresses,'Latitude':latitude, 'Longitude': longitude})
df.to_csv('filename.csv', index=False, encoding='latin-1')
Edit
Pub: 17 Apr 2020 13:09 UTC
Edit: 17 Apr 2020 13:12 UTC
Views: 294