<jupyter_start><jupyter_text>Web Scraping Challenge  Part 1 - Scraping NASA Mars News * Scrape the [NASA Mars News Site](https://mars.nasa.gov/news/) and collect the latest News Title and Paragraph Text. Assign the text to variables that you can reference later.<jupyter_code># importing the dependencies that I think I will need
import requests
from pprint import pprint
from bs4 import BeautifulSoup as bs
from datetime import datetime as dt
import pandas as pd
from splinter import Browser
import os
import re
# Establishing the executable path of the chromedriver
executable_path = {'executable_path': 'chromedriver.exe'}
browser = Browser('chrome', **executable_path, headless=False)
# Getting the url and establishing the soup format thing 
url = 'https://mars.nasa.gov/news/'
response = requests.get(url)
browser.visit(url)
html = browser.html
soup_title = bs(response.text, 'html.parser')
soup_para = bs(html, 'html.parser')

title_not_clean = soup_title.find('div', class_='content_title').a.text
paragraph = soup_para.find('div', class_='article_teaser_body').text

print(title_not_clean)
print(paragraph)
title_clean = title_not_clean.replace("\n","")
browser.quit()

print(title_clean)
print(paragraph)<jupyter_output><NAME> Attached to NASA's Perseverance Rover
The team has learned to meet new challenges as they work remotely on the Mars mission.<jupyter_text>JPL Mars Space Images - Featured Image<jupyter_code>executable_path = {'executable_path': 'chromedriver.exe'}
browser = Browser('chrome', **executable_path, headless=False)
url = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
browser.visit(url)
html = browser.html
soup = bs(html, 'html.parser')
print(soup.prettify())
article = soup.find('article', class_='carousel_item')
print(article)
image_extension  = article['style'].split("('", 1)[1].split("')")[0]
print(image_extension)
featured_img_url = f'https://www.jpl.nasa.gov{image_extension}'
browser.quit()
print(featured_img_url)<jupyter_output>jpl.nasa.gov/spaceimages/images/wallpaper/PIA16021-1920x1200.jpg<jupyter_text>Mars Weather<jupyter_code>url = 'https://twitter.com/marswxreport'
response = requests.get(url)
soup = bs(response.text, 'html.parser')
print(soup.prettify())
weather = soup.find('p', class_='tweet-text').text
weather_update = re.sub(r'\w+:\/{2}[\d\w-]+(\.[\d\w-]+)*(?:(?:\/[^\s/]*))*', '', weather)
print(weather_update)<jupyter_output>“It's classic, textbook NASA, We're presented with a problem and we figure out how to make things work. Mars isn't standing still for us; we're still exploring." MER Science Operations Team Chief. …<jupyter_text>Mars Facts<jupyter_code>executable_path = {'executable_path': 'chromedriver.exe'}
browser = Browser('chrome', **executable_path, headless=False)
url = 'https://space-facts.com/mars/'
browser.visit(url)
html = browser.html
soup = bs(html, 'html.parser')
table_html = soup.find_all('table')
mars_facts = pd.read_html(html)[1]
mars_facts.columns = ['','Mars Values']
mars_facts.set_index('', inplace = True)
browser.quit()
mars_facts
mars_facts.to_html(os.path.join('templates','mars_facts.html'))
mars_facts<jupyter_output><empty_output><jupyter_text>Mars Hemispheres<jupyter_code>executable_path = {'executable_path': 'chromedriver.exe'}
browser = Browser('chrome', **executable_path, headless=False)
url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'
browser.visit(url)
html = browser.html
soup = bs(html, 'html.parser')
results_item_list = soup.find('div', class_='collapsible results').find_all('div', class_='item')
print(results_item_list)
hemisphere_image_urls = []
    
for h in results_item_list:
    title = h.find('h3', class_=None).text
    title = title.replace(" Enhanced","")
    url = h.find('a')['href']
    url_1 = f'https://astrogeology.usgs.gov{url}'
    browser.visit(url_1)
    html = browser.html
    soup_image = bs(html,'html5lib')
    img_url = soup_image.find("div", class_="downloads").a['href']
    hemisphere_image_urls.append({"title": title, "img_url": img_url})
    
browser.quit()
hemisphere_image_urls<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1477438136826783, 'fraction_numerical': 0.006307617661329452, 'mean_word_length': 6.607011070110701, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '483597', 'license': 'ADSL', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1405, 'n_words': 301, 'path': 'mission_to_mars.ipynb', 'repo_name': 'AymanSulaiman/web-scraping-challenge', 'size': '4131'}