<jupyter_start><jupyter_text>Dependencies<jupyter_code>from bs4 import BeautifulSoup
import requests
import pymongo
import pandas as pd

from splinter import Browser
from selenium import webdriver
executable_path = {"executable_path": "chromedriver.exe"}
# Initialize PyMongo to work with MongoDBs
conn = 'mongodb://localhost:27017'
client = pymongo.MongoClient(conn)<jupyter_output><empty_output><jupyter_text>NEWS ARTICLE<jupyter_code>def recentMarsNews():
    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=Browser("chrome", **executable_path, headless=False)
    browser.visit(url)
    html=browser.html
    browser.quit()
    soup = BeautifulSoup(html, "html.parser")
    title=soup.find('div', class_="content_title").text
    text=soup.find('div', class_="rollover_description_inner").text
    return(title, text)
recentMarsNews()<jupyter_output>NASA's Curiosity Rover Finds an Ancient Oasis on Mars: New evidence suggests salty, shallow ponds once dotted a Martian crater — a sign of the planet's drying climate.<jupyter_text>Full-size image<jupyter_code>def findMarsPic():
    img_url_pg="https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars"
    img_browser=Browser("chrome", **executable_path, headless=False)
    img_browser.visit(img_url_pg)
    img_html=img_browser.html
    img_soup=BeautifulSoup(img_html, "html.parser")
    featured_img=img_url_pg+(img_soup.find('img', class_="thumb")["src"])
    return(featured_img)

findMarsPic()<jupyter_output><empty_output><jupyter_text>Mars Weather:<jupyter_code>def currentMarsWeather():
    weather_url="https://twitter.com/marswxreport?lang=en"
    weather_browser=Browser("chrome", **executable_path, headless=False)
    weather_browser.visit(weather_url)
    weather_html=weather_browser.html
    weather_soup=BeautifulSoup(weather_html, 'html.parser')
    weather_browser.quit()
    return (weather_soup.find('div', class_="js-tweet-text-container").text)
currentMarsWeather()<jupyter_output><empty_output><jupyter_text>Mars Facts:<jupyter_code>def getMarsFacts():
    fact_url="https://space-facts.com/mars/"
    fact_browser=Browser("chrome", **executable_path, headless=False)
    fact_browser.visit(fact_url)
    fact_table=(pd.read_html(fact_browser.html))
    fact_table=fact_table[1]
    fact_table.columns=['Mars', 'Data']
    fact_table=fact_table.to_html(classes='marsinformation')
    fact_table=fact_table.replace('\n', ' ')
    
  
      
    fact_browser.quit()
   
    return (fact_table)

def getMarsFacts2():
    fact_url="https://space-facts.com/mars/"
    fact_browser=Browser("chrome", **executable_path, headless=False)
    fact_browser.visit(fact_url)
    fact_html=fact_browser.html
    fact_table=pd.read_html(fact_html)
    fact_table.columns=['Mars', 'Da']
    fact_table=fact_table.set_index("Mars")
    return_table=fact_table.to_html(classes='table_info')
    return_table=return_table.replace('/n', ' ')

    return (return_table)
x=getMarsFacts()

x<jupyter_output><empty_output><jupyter_text>Mars Hemispheres<jupyter_code>def getMarsHems():
    base="https://astrogeology.usgs.gov"
    hems_url="https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars"
    hems_browser=Browser("chrome", **executable_path, headless=False)
    hems_browser.visit(hems_url)
    hems_soup=BeautifulSoup(hems_browser.html, 'lxml')
    hems_browser.quit()
    list_img_url=[]
    for x in hems_soup.find_all('div', class_="item"):
        linkx=base+ x.find('a')["href"]
        list_img_url.append(linkx)
    
    return(getEnchancedMarsImg(list_img_url))
 def getEnchancedMarsImg(url_list):
    base="https://astrogeology.usgs.gov"
    browserx=Browser("chrome", **executable_path, headless=False)
    hemisphere_image_urls=[]
    for x in url_list:
        browserx.visit(x)
        xsoup=BeautifulSoup(browserx.html, 'lxml')
        title=xsoup.find('title').text
        title=title.split(" |")
        title=title[0]
        for u in xsoup.find_all('img', class_="wide-image"):
            img_link=base+u["src"]
        img_dic={"title":title, 
                "img_url":img_link}
        hemisphere_image_urls.append(img_dic)
        
    browserx.quit()
    return(hemisphere_image_urls)
        
        
getMarsHems()<jupyter_output>[{'title': 'Cerberus Hemisphere Enhanced', 'img_url': 'https://astrogeology.usgs.gov/cache/images/cfa62af2557222a02478f1fcd781d445_cerberus_enhanced.tif_full.jpg'}, {'title': 'Schiaparelli Hemisphere Enhanced', 'img_url': 'https://astrogeology.usgs.gov/cache/images/3cdd1cbf5e0813bba925c9030d13b62e_schiaparelli_enhanced.tif_full.jpg'}, {'title': 'Syrtis Major Hemisphere Enhanced', 'img_url': 'https://astrogeology.usgs.gov/cache/images/ae209b4e408bb6c3e67b6af38168cf28_syrtis_major_enhanced.tif_full.jpg'}, {'title': 'Valles Marineris Hemisphere Enhanced', 'img_url': 'https://astrogeology.usgs.gov/cache/images/7cf2da4bf549ed01c17f206327be4db7_valles_marineris_enhanced.tif_full.jpg'}]
{'fraction_non_alphanumeric': 0.13416320885200553, 'fraction_numerical': 0.02074688796680498, 'mean_word_length': 5.634338138925295, 'pattern_counts': {'":': 3, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 12, 'lorem ipsum': 0, 'www.': 1, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '209534', 'license': 'ADSL', 'n_tokens_mistral': 1954, 'n_tokens_neox': 1849, 'n_words': 218, 'path': 'Missions_to_Mars/.ipynb_checkpoints/Mission_to_Mars-checkpoint.ipynb', 'repo_name': 'Kev-clark/web-scraping-challenge', 'size': '5061'}