<jupyter_start><jupyter_text>Visit the NASA mars news site<jupyter_code># Visit the mars nasa news site
mnns_url = "https://mars.nasa.gov/news/"
browser.visit(mnns_url)
# delay for loading the page
time.sleep(5)
# Convert the browser html to a soup object and then quit the browser
html = browser.html
soup =  bs(html, 'html.parser')
browser.quit()
# .find() the content title and save it as `news_title`
first_article = soup.find('div', { 'class' : 'list_text'})
# news_title = first_article.find('div', { 'class' : 'content_title'}).text
news_title = first_article.a.text
news_title
# .find() the paragraph text
news_p = first_article.find('div', { 'class' : 'article_teaser_body'}).text
news_p<jupyter_output><empty_output><jupyter_text>JPL Space Images Featured Image<jupyter_code># Visit JPL space images Mars URL
# Reset the executable path and re-initialize the chrome browser in splinter
executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=True)
jpl_url = "https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/index.html"
browser.visit(jpl_url)
time.sleep(5)
# Find and click the full image button
browser.links.find_by_partial_text('FULL IMAGE').click()
# Parse the resulting html with soup
html = browser.html
soup =  bs(html, 'html.parser')
browser.quit()
# find the relative image url
relative_image_url = soup.find('img', class_="fancybox-image")["src"]
relative_image_url
# Use the base url to create an absolute url
base_url = jpl_url.split('index.html')[0]
featured_image_url = base_url + relative_image_url
featured_image_url<jupyter_output><empty_output><jupyter_text>Mars Facts<jupyter_code># Create a dataframe from the space-facts.com mars page
url = "https://space-facts.com/mars/"
tables = pd.read_html(url, header=None)
mars_df = tables[0]
mars_df
# clean the dataframe and export to HTML
#  Set columns, set index, export to HTML file
mars_df.columns = ['parameter', 'value']
mars_df.set_index('parameter', inplace=True)
mars_df.to_html('visualizations/table.html')

# Replace newline character, strip extra columns, rows
html_table = mars_df.to_html()
html_table.replace('\n','')
mars_df<jupyter_output><empty_output><jupyter_text>Hemispheres<jupyter_code># visit the USGS astrogeology page for hemisphere data from Mars
executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=True)
# Visit the USGS astrogeology page
usgs_url = "https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars"
browser.visit(usgs_url)
# Delay for loading the page
time.sleep(5)

# First, get a list of all of the hemispheres

# Parse the resulting html with soup
html = browser.html
soup =  bs(html, 'html.parser')

# List of hemispheres
hemispheres_h3 = soup.div.find_all('h3')
hemispheres = [x.text.replace(' Enhanced', '') for x in hemispheres_h3]
hemispheres
# Next, loop through those links, click the link, find the sample anchor, return the href

hemisphere_image_urls = []

for hemisphere in hemispheres:
    # Click into hemisphere page
    browser.links.find_by_partial_text(hemisphere).click()

    # We have to find the elements on each loop to avoid a stale element exception
    html = browser.html
    soup =  bs(html, 'html.parser')
    sample = soup.find('div', { "class" : "downloads"})
    # Next, we find the Sample image anchor tag and extract the href
    sample_image_url = sample.a['href']
    
    # Get Hemisphere title
    hemisphere_title = hemisphere

    # Append hemisphere object to list
    hemisphere_object = {
        "img_url" : sample_image_url,
        "title"   : hemisphere_title
    }
    hemisphere_image_urls.append(hemisphere_object)
    
    # Navigate backwards with browser.back()
    browser.back()
    
# Quit the browser
browser.quit()
# view the hemisphere urls to make sure they look good
hemisphere_image_urls<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11074754593506167, 'fraction_numerical': 0.0027686886483765417, 'mean_word_length': 5.287974683544304, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '648003', 'license': 'Apache-2.0', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1307, 'n_words': 358, 'path': 'Mission_to_Mars/mission_to_mars.ipynb', 'repo_name': 'githotirado/web-scraping-challenge', 'size': '3973'}