<jupyter_start><jupyter_text>Step 1 - Scraping  NASA Mars News<jupyter_code># Scrape the NASA Mars News Site and collect the latest News Title and Paragraph Text. Assign the text to variables that you can reference later.

# Example:
# news_title = "NASA's Next Mars Mission to Investigate Interior of Red Planet"

# news_p = "Preparation of NASA's next spacecraft to Mars, InSight, has ramped up this summer, on course for launch next May from Vandenberg Air Force Base in central California -- the first interplanetary launch in history from America's West Coast."

executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=False)
# URL of page to be scraped
url = 'https://mars.nasa.gov/news/?page=0&per_page=40&order=publish_date+desc%2Ccreated_at+desc&search=&category=19%2C165%2C184%2C204&blank_scope=Latest'

browser.visit(url)
html = browser.html
soup = bs(html, "html.parser")
# Retrieve the parent divs for all articles
news_title = soup.find_all('div', class_='content_title')
news_p = soup.find_all('div', class_='article_teaser_body')

index_number = input('Which latest news article would you like to preview? (Insert numerical value, e.g. 0,1,2,...) You picked article ')
news_title = news_title[int(index_number)].text
news_p = news_p[int(index_number)].text
print("\n")
print(f'Title: {news_title}')
print('-'*30)
print(f'Preview Paragraph: {news_p}')<jupyter_output>Which latest news article would you like to preview? (Insert numerical value, e.g. 0,1,2,...) You picked article 3


Title: New Study Challenges Long-Held Theory of Fate of Mars' Water
------------------------------
Preview Paragraph: Working with the Navajo Nation, the rover team has named features on Mars with words from the Navajo language.<jupyter_text>JPL Mars Space Images - Featured Image<jupyter_code>image_url = 'https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/index.html'

browser.visit(image_url)
html = browser.html
soup = bs(html, "html.parser")

not_image_url = 'https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/'
space_image_path = soup.find_all('img', class_='headerimage fade-in')[0]["src"]
featured_image_url = not_image_url + space_image_path
# https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/image/featured/mars2.jpg
#     image/featured/mars2.jpg
# if space_image_path=='image/featured/mars2.jpg':
#     print(featured_image_url)
# else:
#     print('Rerun this cell. Trust me.')
print(featured_image_url)<jupyter_output>https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/image/featured/mars1.jpg<jupyter_text>Mars Facts<jupyter_code># Visit the Mars Facts webpage here and use Pandas to scrape the table containing facts about the planet including Diameter, Mass, etc.
# Use Pandas to convert the data to a HTML table string.

mars_facts_url = 'https://space-facts.com/mars/'

# browser.visit(mars_facts_url)
# html = browser.html
# soup = bs(html, "html.parser")


info_tables = pd.read_html(mars_facts_url)
info_tables
mars_info_df = info_tables[0]
mars_info_df
mars_info_html = mars_info_df.to_html()
mars_info_html<jupyter_output><empty_output><jupyter_text>Mars Hemispheres<jupyter_code># Visit the USGS Astrogeology site here to obtain high resolution images for each of Mar's hemispheres.
# You will need to click each of the links to the hemispheres in order to find the image url to the full resolution image.
# Save both the image url string for the full resolution hemisphere image, and the Hemisphere title containing the hemisphere name. Use a Python dictionary to store the data using the keys img_url and title.
# Append the dictionary with the image url string and the hemisphere title to a list. This list will contain one dictionary for each hemisphere.<jupyter_output><empty_output><jupyter_text>Cerberus<jupyter_code>cerberus_url = 'https://astrogeology.usgs.gov/search/map/Mars/Viking/cerberus_enhanced'

not_another_image_url = 'https://astrogeology.usgs.gov/'

browser.visit(cerberus_url)
html = browser.html
soup = bs(html, "html.parser")
cerberus_image_path = soup.find_all('img', class_='wide-image')[0]["src"]

cerberus_image_url = not_another_image_url + cerberus_image_path
print(cerberus_image_url)<jupyter_output>https://astrogeology.usgs.gov//cache/images/f5e372a36edfa389625da6d0cc25d905_cerberus_enhanced.tif_full.jpg<jupyter_text>Schiaparelli<jupyter_code>schiaparelli_url = 'https://astrogeology.usgs.gov/search/map/Mars/Viking/schiaparelli_enhanced'

browser.visit(schiaparelli_url)
html = browser.html
soup = bs(html, "html.parser")
schiaparelli_image_path = soup.find_all('img', class_='wide-image')[0]["src"]

schiaparelli_image_url = not_another_image_url + schiaparelli_image_path
print(schiaparelli_image_url)<jupyter_output>https://astrogeology.usgs.gov//cache/images/3778f7b43bbbc89d6e3cfabb3613ba93_schiaparelli_enhanced.tif_full.jpg<jupyter_text>Syrtis<jupyter_code>syrtis_url = 'https://astrogeology.usgs.gov/search/map/Mars/Viking/syrtis_major_enhanced'

browser.visit(syrtis_url)
html = browser.html
soup = bs(html, "html.parser")
syrtis_image_path = soup.find_all('img', class_='wide-image')[0]["src"]

syrtis_image_url = not_another_image_url + syrtis_image_path
print(syrtis_image_url)<jupyter_output>https://astrogeology.usgs.gov//cache/images/555e6403a6ddd7ba16ddb0e471cadcf7_syrtis_major_enhanced.tif_full.jpg<jupyter_text>Valles<jupyter_code>valles_url = 'https://astrogeology.usgs.gov/search/map/Mars/Viking/valles_marineris_enhanced'

browser.visit(valles_url)
html = browser.html
soup = bs(html, "html.parser")
valles_image_path = soup.find_all('img', class_='wide-image')[0]["src"]

valles_image_url = not_another_image_url + valles_image_path
print(valles_image_url)<jupyter_output>https://astrogeology.usgs.gov//cache/images/b3c7c6c9138f57b4756be9b9c43e3a48_valles_marineris_enhanced.tif_full.jpg<jupyter_text>Hemisphere Image urls<jupyter_code>hemisphere_image_urls_test = [
    {"title": "Valles Marineris Hemisphere", "img_url": f"{cerberus_image_url}"},
    {"title": "Cerberus Hemisphere", "img_url": f"{schiaparelli_image_url}"},
    {"title": "Schiaparelli Hemisphere", "img_url": f"{syrtis_image_url}"},
    {"title": "Syrtis Major Hemisphere", "img_url": f"{valles_image_url}"},
]
hemisphere_image_urls_test
# mars_data = {"hemisphere": hemisphere_image_urls_test,
#              "mars_stats": mars_info_df,
#              "mars_url": }<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11826788762998604, 'fraction_numerical': 0.01769362098401366, 'mean_word_length': 6.423963133640553, 'pattern_counts': {'":': 11, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 15, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '381197', 'license': 'ADSL', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2314, 'n_words': 466, 'path': 'Mission_to_Mars/mission_to_mars.ipynb', 'repo_name': 'ytran010/web-scraping-challenge', 'size': '6443'}