# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

 # Dependencies
from bs4 import BeautifulSoup as bs
import requests
from splinter import Browser
import time
import pandas as pd

# # !which chromedriver
executable_path = {'executable_path': '/usr/local/bin/chromedriver'}
browser = Browser('chrome', **executable_path, headless=False)

url ="https://mars.nasa.gov/news/"
browser.visit(url)

browser.is_element_present_by_css("ul.item_list li.slide", wait_time = 1)

html = browser.html
news_soup = bs(html, 'html.parser')
side_element = news_soup.select_one("ul.item_list li.slide")


news_title = side_element.find("div", class_="content_title").get_text()
news_title

news_p = side_element.find('div', class_="article_teaser_body").get_text()
news_p

url2 = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
browser.visit(url2)

browser.links.find_by_partial_text('FULL').click()

time.sleep(1)
browser.links.find_by_partial_text('more info').click()

html = browser.html
soup = bs(html, 'html.parser')

image = soup.select_one('figure.lede a img').get("src")
image

core_url = "https://www.jpl.nasa.gov"
final_image = core_url + image
final_image

url3 = "https://space-facts.com/mars/"

mars_table = pd.read_html(url3)
mars_table = mars_table[0]
mars_table

mars_table.columns=["Description", "Mars"]
mars_table.set_index("Description", inplace = True)
mars_table

mars_table.to_html('mars_fact_table.html')

url4 = "https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars"

browser.visit(url4)

html_hemisphere = browser.html
soup_hemisphere = bs(html_hemisphere,'html.parser')

# +
hemispheres = soup_hemisphere.find_all('div', class_='item')

all_hemis_list = []
main_url = "https://astrogeology.usgs.gov"
for x in hemispheres:
    #get title
    title = x.find('h3').text
    
    #Store a link that leads to the full image
    temp_img = x.find('a', class_ = 'itemLink product-item')['href']
    
    browser.visit(main_url + temp_img)
    
    temp_img_html = browser.html
    soup_each_hemis = bs(temp_img_html, "html.parser")
    
    #scrap full image source
    full_img_url = main_url + soup_each_hemis.find('img', class_="wide-image")['src']
    
    #append to the list
    all_hemis_list.append({"title": title, "img_url": full_img_url})

    
    
#Display resulted list
all_hemis_list
    

# -



StarcoderdataJupyterScriptsDedupFiltered