<jupyter_start><jupyter_text>Mission To Mars  NASA Mars NewsScrape title/blurb from [Nasa Mars News](https://mars.nasa.gov/news/)<jupyter_code>from splinter import Browser 
from bs4 import BeautifulSoup
from webdriver_manager.chrome import ChromeDriverManager
import time

def init_browser():
    # @NOTE: Replace the path with your actual path to the chromedriver
    executable_path = { "executable_path": ChromeDriverManager().install()}
    return Browser("chrome", **executable_path, headless=False)

def scrape_nasa_mars_news():
    url = 'https://mars.nasa.gov/news/'

    browser = init_browser()
    browser.visit(url)
    time.sleep(1)
    html = browser.html
    browser.quit()
    
    soup = BeautifulSoup(html, "html.parser")
    
    slides = soup.find_all('li', class_='slide')
#     print(slides[0].prettify())

    title = slides[0].find('div', class_='content_title')
    link = title.find('a')
    teaser = slides[0].find('div', class_='article_teaser_body')
    
    return link.text.strip(), teaser.text.strip()
    

news_tuple = scrape_nasa_mars_news()
# print(news_tuple)
news_title, news_p = news_tuple
print(news_title)
print(news_p)<jupyter_output>====== WebDriver manager ======
Current google-chrome version is 94.0.4606
Get LATEST driver version for 94.0.4606
Driver [/Users/jagjeetkhalsa/.wdm/drivers/chromedriver/mac64/94.0.4606.41/chromedriver] found in cache<jupyter_text>JPL Space Featured ImageScrape featured image from [Jet Propulsion Laboratory](https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/index.html)<jupyter_code>from urllib.parse import urljoin

def scrape_jpl_featured_image():
    browser = init_browser()

    url = 'https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/index.html'

    browser.visit(url)
    html = browser.html

    browser.quit()
    
    soup = BeautifulSoup(html, "html.parser")
    header = soup.find('div', class_='header')
    text_area = header.find('div', class_='floating_text_area')
    link = text_area.find('a', class_='showimg')

    #For getting the base URL see:
    #https://stackoverflow.com/questions/35616434/how-can-i-get-the-base-of-a-url-in-python
    return urljoin(url, '.') + link['href']    

featured_image_url = scrape_jpl_featured_image()
print(featured_image_url)<jupyter_output>====== WebDriver manager ======
Current google-chrome version is 94.0.4606
Get LATEST driver version for 94.0.4606
Driver [/Users/jagjeetkhalsa/.wdm/drivers/chromedriver/mac64/94.0.4606.41/chromedriver] found in cache<jupyter_text>Mars Space Facts TableScrape table from [Space-Facts.com](https://space-facts.com/mars/) using Pandas<jupyter_code>import pandas as pd
import requests

def scrape_mars_space_facts():

    url = 'https://space-facts.com/mars/'
    tables = pd.read_html(requests.get(url).text)
    df = tables[2]
    return df.to_html(classes='table table-striped', header=False, index=False)

mars_space_facts_HTML = scrape_mars_space_facts()
print(mars_space_facts_HTML)<jupyter_output><table border="1" class="dataframe table table-striped">
  <tbody>
    <tr>
      <td>Equatorial Diameter:</td>
      <td>6,792 km</td>
    </tr>
    <tr>
      <td>Polar Diameter:</td>
      <td>6,752 km</td>
    </tr>
    <tr>
      <td>Mass:</td>
      <td>6.39 × 10^23 kg (0.11 Earths)</td>
    </tr>
    <tr>
      <td>Moons:</td>
      <td>2 (Phobos &amp; Deimos)</td>
    </tr>
    <tr>
      <td>Orbit Distance:</td>
      <td>227,943,824 km (1.38 AU)</td>
    </tr>
    <tr>
      <td>Orbit Period:</td>
      <td>687 days (1.9 years)</td>
    </tr>
    <tr>
      <td>Surface Temperature:</td>
      <td>-87 to -5 °C</td>
    </tr>
    <tr>
      <td>First Record:</td>
      <td>2nd millennium BC</td>
    </tr>
    <tr>
      <td>Recorded By:</td>
      <td>Egyptian astronomers</td>
    </tr>
  </tbody>
</table><jupyter_text>Astrogeology Mars HemispheresScrape title/image urls from [astrogeology.usgs.gov](https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars).<jupyter_code>import time

url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'

def scrape_mars_hemispheres():
    hemisphereList = []
    url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'

    browser = init_browser()
    browser.visit(url)
    html = browser.html
    
    soup = BeautifulSoup(html, "html.parser")
    mars_section = soup.find("section", {"id": "results-accordian"})
    # mars_section = soup.find("section")
    descriptions = mars_section.find_all('div', class_='description')

    # print(mars_section.prettify())
    # print(descriptions)

    for desc in descriptions:
        marsDict = {}
        # print(desc.prettify())
        title = desc.find("h3").text
        # print(title)
        marsDict['title'] = title
        link = desc.find("a", class_='product-item')

        link_url = urljoin(url, '/') + link['href']
        # print(link_url)
        browser.visit(link_url)
        link_html = browser.html
        time.sleep(1)

        # print(link_html)
        link_soup = BeautifulSoup(link_html, 'html.parser')
        download = link_soup.find("div", class_="downloads")
        img_anchor = download.find("a")
        # print(download)
        # print(img_anchor)
        # print(img_anchor['href'])
        marsDict['img_url']=img_anchor['href']
        hemisphereList.append(marsDict)

    browser.quit()
   
    return hemisphereList
    
#     browser.quit()

#     return html
#     soup = BeautifulSoup(html, "html.parser")

hemisphere_list = scrape_mars_hemispheres()
print(hemisphere_list)<jupyter_output>====== WebDriver manager ======
Current google-chrome version is 94.0.4606
Get LATEST driver version for 94.0.4606
Driver [/Users/jagjeetkhalsa/.wdm/drivers/chromedriver/mac64/94.0.4606.41/chromedriver] found in cache<jupyter_text>Combine Mars DataReturn a single object with all the data<jupyter_code>def scrape_mars_data(): 
    mars_dict = {}
    
    # Mars News
    news_tuple = scrape_nasa_mars_news()
    news_title, news_p = news_tuple
    mars_dict['news_title'] = news_title
    mars_dict['news_p'] = news_p
    
    # JPL
    mars_dict['featured_image_url'] = scrape_jpl_featured_image()

    # Mars Space Facts
    mars_dict['space_facts_HTML'] = scrape_mars_space_facts()

    mars_dict['hemispheres'] = scrape_mars_hemispheres()
    
    return mars_dict

mars_dict = scrape_mars_data()

print(mars_dict)<jupyter_output>====== WebDriver manager ======
Current google-chrome version is 94.0.4606
Get LATEST driver version for 94.0.4606
Driver [/Users/jagjeetkhalsa/.wdm/drivers/chromedriver/mac64/94.0.4606.41/chromedriver] found in cache


====== WebDriver manager ======
Current google-chrome version is 94.0.4606
Get LATEST driver version for 94.0.4606
Driver [/Users/jagjeetkhalsa/.wdm/drivers/chromedriver/mac64/94.0.4606.41/chromedriver] found in cache


====== WebDriver manager ======
Current google-chrome version is 94.0.4606
Get LATEST driver version for 94.0.4606
Driver [/Users/jagjeetkhalsa/.wdm/drivers/chromedriver/mac64/94.0.4606.41/chromedriver] found in cache
{'fraction_non_alphanumeric': 0.1424561403508772, 'fraction_numerical': 0.030175438596491227, 'mean_word_length': 3.744340878828229, 'pattern_counts': {'":': 2, '<': 74, '<?xml version=': 0, '>': 74, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '581537', 'license': 'MIT', 'n_tokens_mistral': 2741, 'n_tokens_neox': 2538, 'n_words': 455, 'path': 'mission_to_mars.ipynb', 'repo_name': 'Jagjeet/web-scraping-challenge', 'size': '7125'}