<jupyter_start><jupyter_text>NASA Mars News<jupyter_code># Set up Dependencies
import pandas as pd
from bs4 import BeautifulSoup as bs
import pymongo
import requests

# use Google Chrome with Splinter
from webdriver_manager.chrome import ChromeDriverManager
from splinter import Browser
from selenium import webdriver
# ADD Splinter: an abstraction layer on top of existing browser automation tools
executable_path = {'executable_path':ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=False)
# Set scraper to retreive image from Mars url 
mars_url = 'https://redplanetscience.com/'
browser.visit(mars_url)

html = browser.html

mars_soup = bs(html, 'html.parser')
# Pull news title and paragraph teaser info

title = mars_soup.find('div', class_='content_title').text
teaser = mars_soup.find('div', class_='article_teaser_body').text
# Display results
print(title)
print(' ')
print(teaser)<jupyter_output>NASA's Mars 2020 <NAME> for Microscopic Fossils
 
A new paper identifies a ring of minerals at the rover's landing site that are ideal for fossilizing microbial life.<jupyter_text>JPL Mars Space Images - Featured Image<jupyter_code># Set scraper to retreive image from JPL url 

jpl_url = 'https://spaceimages-mars.com/'
browser.visit(jpl_url)

html = browser.html

jpl_soup = bs(html, 'lxml')
# Pull image
image = jpl_soup.find_all('img', class_= "headerimage fade-in")[0]["src"]

# Create featured image url
featured_image_url = jpl_url + image
print(featured_image_url)<jupyter_output>https://spaceimages-mars.com/image/featured/mars1.jpg<jupyter_text>Mars Facts<jupyter_code># Use the read_html function in Pandas to automatically scrape tabular data from the Mars Facts url
url = 'https://galaxyfacts-mars.com/'

# Read table
mars_table = pd.read_html(url)
mars_table
# Slice off any Mars dataframe using normal indexing
facts_df = mars_table[0]
facts_df.columns = ['Description', 'Mars', 'Earth']
facts_df
# Create html table from Dataframe
mars_html_table = facts_df.to_html()
mars_html_table
# Remove newlines
mars_html_table.replace('\n', '')
# View html file
print(mars_html_table)<jupyter_output><table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Description</th>
      <th>Mars</th>
      <th>Earth</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Mars - Earth Comparison</td>
      <td>Mars</td>
      <td>Earth</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Diameter:</td>
      <td>6,779 km</td>
      <td>12,742 km</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Mass:</td>
      <td>6.39 × 10^23 kg</td>
      <td>5.97 × 10^24 kg</td>
    </tr>
    <tr>
      <th>3</th>
      <td>Moons:</td>
      <td>2</td>
      <td>1</td>
    </tr>
    <tr>
      <th>4</th>
      <td>Distance from Sun:</td>
      <td>227,943,824 km</td>
      <td>149,598,262 km</td>
    </tr>
    <tr>
      <th>5</th>
      <td>Length of Year:</td>
      <td>687 Earth days</td>
      <td>365.24 days</td>
    </tr>
    <tr>
      <th>6</th>
      <td>Temperature:</td>
      <td>-87 to -5 °C</td>
      <td>-88 to 58°C</td>
  [...]<jupyter_text>Mars Hemispheres<jupyter_code># Set scraper to retreive images from Mars Hemisheres url
hems_url = 'https://marshemispheres.com/'
browser.visit(hems_url)

html = browser.html

hems_soup = bs(html, 'lxml')
# Locate and pull hemisphere data
all_hemispheres = hems_soup.find('div', class_= "collapsible results")

# Locate and pull individual hemisphere data
each_hemisphere = all_hemispheres.find_all('div', class_='item')
hems_link = []

# Iterate through to locate each hemisphere title and image

for each in each_hemisphere:
    # Find the title of the image
    hems_title = each.find("h3").text
    hems_title = hems_title.replace("Enhanced", "")
    
    #Find the image url
    image = each.find('img', class_= "thumb")["src"]

    # Create featured image url
    img_url = hems_url + image
    
    # Create dictionary for title and image info
    hems_dict = {}
    hems_dict['title'] = hems_title
    hems_dict['img_url'] = img_url
    
    hems_link.append(hems_dict)
    
print(hems_link)
#     print(image)
# Store all scraped data in a mars dictionary
mars_data_dict = {
    "news_title": title,
    "news_info": teaser,
    "featured_image_url": featured_image_url,
    "fun_facts_table": mars_html_table,
    "hemisphere_info": hems_link
}
mars_data_dict<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1319910514541387, 'fraction_numerical': 0.016778523489932886, 'mean_word_length': 3.7869379014989293, 'pattern_counts': {'":': 5, '<': 98, '<?xml version=': 0, '>': 98, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '438758', 'license': 'ADSL', 'n_tokens_mistral': 1715, 'n_tokens_neox': 1622, 'n_words': 395, 'path': 'web-scraping-challenge/Missions_to_Mars/mission_to_mars.ipynb', 'repo_name': 'almulldreyer/web-scraping-challenge', 'size': '4473'}