Created
October 15, 2021 19:00
-
-
Save weiw11/b93d9e538a5daca5b90a6bfe5f454b8e to your computer and use it in GitHub Desktop.
Get location data of all states from freecampsites.net
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
states = ["Alaska", | |
"Alabama", | |
"Arkansas", | |
"American Samoa", | |
"Arizona", | |
"California", | |
"Colorado", | |
"Connecticut", | |
"District of Columbia", | |
"Delaware", | |
"Florida", | |
"Georgia", | |
"Guam", | |
"Hawaii", | |
"Iowa", | |
"Idaho", | |
"Illinois", | |
"Indiana", | |
"Kansas", | |
"Kentucky", | |
"Louisiana", | |
"Massachusetts", | |
"Maryland", | |
"Maine", | |
"Michigan", | |
"Minnesota", | |
"Missouri", | |
"Mississippi", | |
"Montana", | |
"North Carolina", | |
"North Dakota", | |
"Nebraska", | |
"New Hampshire", | |
"New Jersey", | |
"New Mexico", | |
"Nevada", | |
"New York", | |
"Ohio", | |
"Oklahoma", | |
"Oregon", | |
"Pennsylvania", | |
"Puerto Rico", | |
"Rhode Island", | |
"South Carolina", | |
"South Dakota", | |
"Tennessee", | |
"Texas", | |
"Utah", | |
"Virginia", | |
"Virgin Islands", | |
"Vermont", | |
"Washington", | |
"Wisconsin", | |
"West Virginia", | |
"Wyoming"] | |
state = "New York" | |
headers = { | |
'Accept': 'application/json', | |
'Host': 'freecampsites.net', | |
'Referer': 'https://freecampsites.net/', | |
'TE': 'trailers' | |
} | |
for x in states: | |
url = 'https://freecampsites.net/wp-content/themes/freecampsites/androidApp.php?region=' + x + '&advancedSearch=%7B%7D' | |
response = requests.get(url, headers=headers) | |
data = response.json() | |
with open(x + '.json', 'w') as outf: | |
if data.get("resultList") is not None: | |
for elem in data["resultList"]: | |
if elem.get("url") is not None: | |
del elem["url"] | |
if elem.get("excerpt") is not None: | |
del elem["excerpt"] | |
if elem.get("ratings_average") is not None: | |
del elem["ratings_average"] | |
if elem.get("ratings_value") is not None: | |
del elem["ratings_value"] | |
if elem.get("ratings_count") is not None: | |
del elem["ratings_count"] | |
if elem.get("rating") is not None: | |
del elem["rating"] | |
if elem.get("table_row") is not None: | |
del elem["table_row"] | |
json.dump(data, outf, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment