Skip to content

Instantly share code, notes, and snippets.

@mitchellvitez
Last active February 21, 2019 03:40
Show Gist options
  • Select an option

  • Save mitchellvitez/7104a336b7c611f61920f3c68c6ee445 to your computer and use it in GitHub Desktop.

Select an option

Save mitchellvitez/7104a336b7c611f61920f3c68c6ee445 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
def soupify(url):
page = requests.get(url)
return BeautifulSoup(page.text, 'html.parser')
parks = soupify('https://www.nps.gov/planyourvisit/fee-free-parks-state.htm').find_all('a')
for park in parks:
if park['href'].startswith('https://www.nps.gov'):
address = soupify(park['href']).find(attrs={'itemprop': 'address'})
if address:
print(park.contents[0])
print(park['href'])
print(' '.join(address.text.split()))
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment