<jupyter_start><jupyter_text>Mission to Mars<jupyter_code># Dependencies and Setup
from bs4 import BeautifulSoup
from splinter import Browser
import pandas as pd<jupyter_output><empty_output><jupyter_text>Mac<jupyter_code># Set Executable Path & Initialize Chrome Browser
executable_path = {"executable_path": "/usr/local/bin/chromedriver"}
browser = Browser("chrome", **executable_path, headless=False)<jupyter_output><empty_output><jupyter_text>Windows<jupyter_code># Set Executable Path & Initialize Chrome Browser
# executable_path = {"executable_path": "./chromedriver.exe"}
# browser = Browser("chrome", **executable_path)<jupyter_output><empty_output><jupyter_text>NASA Mars News<jupyter_code># Visit the NASA Mars News Site
url = "https://mars.nasa.gov/news/"
browser.visit(url)
# Parse Results HTML with BeautifulSoup
# Find Everything Inside:
#   <ul class="item_list">
#     <li class="slide">

html = browser.html
news_soup = BeautifulSoup(html, "html.parser")
slide_element = news_soup.select_one("ul.item_list li.slide")
slide_element.find("div", class_="content_title")
# Scrape the Latest News Title
# Use Parent Element to Find First <a> Tag and Save it as news_title
news_title = slide_element.find("div", class_="content_title").get_text()
print(news_title)
# Scrape the Latest Paragraph Text
news_paragraph = slide_element.find("div", class_="article_teaser_body").get_text()
print(news_paragraph)<jupyter_output>The first helicopter to fly on Mars had its first flight on Earth.<jupyter_text>JPL Mars Space Images - Featured Image<jupyter_code># Visit the NASA JPL (Jet Propulsion Laboratory) Site
executable_path = {"executable_path": "/usr/local/bin/chromedriver"}
browser = Browser("chrome", **executable_path)
url = "https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars"
browser.visit(url)
# Ask Splinter to Go to Site and Click Button with Class Name full_image
# <button class="full_image">Full Image</button>
full_image_button = browser.find_by_id("full_image")
full_image_button.click()
# Find "More Info" Button and Click It
browser.is_element_present_by_text("more info", wait_time=1)
more_info_element = browser.find_link_by_partial_text("more info")
more_info_element.click()
# Parse Results HTML with BeautifulSoup
html = browser.html
image_soup = BeautifulSoup(html, "html.parser")
img_url = image_soup.select_one("figure.lede a img").get("src")
img_url
# Use Base URL to Create Absolute URL
img_url = f"https://www.jpl.nasa.gov{img_url}"
print(img_url)<jupyter_output>https://www.jpl.nasa.gov/spaceimages/images/largesize/PIA16021_hires.jpg<jupyter_text>Mars Weather<jupyter_code># Visit the Mars Weather Twitter Account
executable_path = {"executable_path": "/usr/local/bin/chromedriver"}
browser = Browser("chrome", **executable_path, headless=False)
url = "https://twitter.com/marswxreport?lang=en"
browser.visit(url)
# Parse Results HTML with BeautifulSoup
html = browser.html
weather_soup = BeautifulSoup(html, "html.parser")
# Find a Tweet with the data-name `Mars Weather`
mars_weather_tweet = weather_soup.find("div", 
                                       attrs={
                                           "class": "tweet", 
                                            "data-name": "Mars Weather"
                                        })
# Search Within Tweet for <p> Tag Containing Tweet Text
mars_weather = mars_weather_tweet.find("p", "tweet-text").get_text()
print(mars_weather)<jupyter_output>InSight sol 115 (2019-03-24) low -96.0ºC (-140.7ºF) high -15.5ºC (4.1ºF)
pressure at 7.30 hPapic.twitter.com/01vh3kQISH<jupyter_text>Mars Facts<jupyter_code># Visit the Mars Facts Site Using Pandas to Read
mars_df = pd.read_html("https://space-facts.com/mars/")[0]
print(mars_df)
mars_df.columns=["Description", "Value"]
mars_df.set_index("Description", inplace=True)
mars_df<jupyter_output>0                              1
0  Equatorial Diameter:                       6,792 km
1       Polar Diameter:                       6,752 km
2                 Mass:  6.42 x 10^23 kg (10.7% Earth)
3                Moons:            2 (Phobos & Deimos)
4       Orbit Distance:       227,943,824 km (1.52 AU)
5         Orbit Period:           687 days (1.9 years)
6  Surface Temperature:                  -153 to 20 °C
7         First Record:              2nd millennium BC
8          Recorded By:           Egyptian astronomers<jupyter_text>Mars Hemispheres<jupyter_code># Visit the USGS Astrogeology Science Center Site
executable_path = {"executable_path": "/usr/local/bin/chromedriver"}
browser = Browser("chrome", **executable_path, headless=False)
url = "https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars"
browser.visit(url)
hemisphere_image_urls = []

# Get a List of All the Hemispheres
links = browser.find_by_css("a.product-item h3")
for item in range(len(links)):
    hemisphere = {}
    
    # Find Element on Each Loop to Avoid a Stale Element Exception
    browser.find_by_css("a.product-item h3")[item].click()
    
    # Find Sample Image Anchor Tag & Extract <href>
    sample_element = browser.find_link_by_text("Sample").first
    hemisphere["img_url"] = sample_element["href"]
    
    # Get Hemisphere Title
    hemisphere["title"] = browser.find_by_css("h2.title").text
    
    # Append Hemisphere Object to List
    hemisphere_image_urls.append(hemisphere)
    
    # Navigate Backwards
    browser.back()
hemisphere_image_urls<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11245421245421246, 'fraction_numerical': 0.0173992673992674, 'mean_word_length': 4.08, 'pattern_counts': {'":': 7, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 7, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '172607', 'license': 'MIT', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1772, 'n_words': 415, 'path': 'Mission_to_Mars.ipynb', 'repo_name': 'kayambi/Mission-To-Mars-HW', 'size': '5460'}