Web-Scraping-Project--Mission-to-Mars
In this Project, I will build a web application that scrapes various websites for data related to the Mission to Mars and displays the information in a single HTML page. The following outlines what I needed to do.
Step 1 - Scraping
Completed the initial scraping using Jupyter Notebook, BeautifulSoup, Pandas, and Requests/Splinter.
- Created a Jupyter Notebook file called
mission_to_mars.ipynb
and use this to complete all of your scraping and analysis tasks. The following outlines what I needed to scrape.
NASA Mars News
- Scraped the Mars News Site and collected the latest News Title and Paragraph Text. Assigned the text to variables that I could reference later.
JPL Mars Space Images - Featured Image
-
Visited the url for the Featured Space Image site here.
-
Used splinter to navigate the site and find the image url for the current Featured Mars Image and assign the url string to a variable called
featured_image_url
. -
Made sure to find the image url to the full size
.jpg
image. -
Made sure to save a complete url string for this image.
# Example:
featured_image_url = 'https://spaceimages-mars.com/image/featured/mars2.jpg'
Mars Facts
-
Visited the Mars Facts webpage here and used Pandas to scrape the table containing facts about the planet including Diameter, Mass, etc.
-
Used Pandas to convert the data to a HTML table string.
Mars Hemispheres
-
Visited the astrogeology site here to obtain high resolution images for each of Mar's hemispheres.
-
I needed to click each of the links to the hemispheres in order to find the image url to the full resolution image.
-
Saved both the image url string for the full resolution hemisphere image, and the Hemisphere title containing the hemisphere name. Used a Python dictionary to store the data using the keys
img_url
andtitle
. -
Appended the dictionary with the image url string and the hemisphere title to a list. This list contained one dictionary for each hemisphere.
# Example:
hemisphere_image_urls = [
{"title": "Valles Marineris Hemisphere", "img_url": "..."},
{"title": "Cerberus Hemisphere", "img_url": "..."},
{"title": "Schiaparelli Hemisphere", "img_url": "..."},
{"title": "Syrtis Major Hemisphere", "img_url": "..."},
]
Step 2 - MongoDB and Flask Application
Used MongoDB with Flask templating to create a new HTML page that displays all of the information that was scraped from the URLs above.
-
Started by converting my Jupyter notebook into a Python script called
scrape_mars.py
with a function calledscrape
that would execute all of my scraping code from above and return one Python dictionary containing all of the scraped data. -
Next, created a route called
/scrape
that imported myscrape_mars.py
script and called myscrape
function.- Stored the return value in Mongo as a Python dictionary.
-
Created a root route
/
that queried my Mongo database and passed the mars data into an HTML template to display the data. -
Created a template HTML file called
index.html
that would take the mars data dictionary and display all of the data in the appropriate HTML elements. Used the following as a guide for what the final product would look like.