# ---
# 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
# ---

import os
import pandas as pd
import pymongo
import requests
import time
from splinter import Browser
from bs4 import BeautifulSoup
from selenium import webdriver

# Setting up splinter, creating the path
executable_path = {"executable_path":"chromedriver.exe"}
browser = Browser("chrome", **executable_path, headless=False)

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

html = browser.html
soup = BeautifulSoup(html, "html.parser")
# -

mars_title = soup.find("div", class_="content_title").text
print(mars_title)

mars_p = soup.find("div", class_="article_teaser_body").text
print(mars_p)

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

browser.click_link_by_partial_text('FULL IMAGE')
time.sleep(5)
browser.click_link_by_partial_text('more info')

img_html = browser.html
soup = BeautifulSoup(img_html, "html.parser")
img_path = soup.find('figure', class_='lede').a['href']
feat_img_url = "https://www.jpl.nasa.gov" + img_path
print(feat_img_url)

weather_url = "https://twitter.com/marswxreport?lang=en"
browser.visit(weather_url)
weather_html = browser.html
soup = BeautifulSoup(weather_html, 'html.parser')
mars_weather = soup.find('p', class_="TweetTextSize TweetTextSize--normal js-tweet-text tweet-text").text
print(mars_weather)

facts_url = "https://space-facts.com/mars/"
browser.visit(facts_url)
facts_html = browser.html
soup = BeautifulSoup(facts_html, 'html.parser')

table_data = soup.find('table', class_="tablepress tablepress-id-mars")

# +
table_all = table_data.find_all('tr')
labels = []
values = []

for tr in table_all:
    td_elements = tr.find_all('td')
    labels.append(td_elements[0].text)
    values.append(td_elements[1].text)
# -

mars_df = pd.DataFrame({
    "Label": labels,
    "Values": values
})
mars_df

facts_table = mars_df.to_html(header=False, index=False)
facts_table

# +
usgs_url = "https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars"
browser.visit(usgs_url)
usgs_html = browser.html
soup = BeautifulSoup(usgs_html, "html.parser")
mars_hemi = []

results = soup.find("div", class_="collapsible results" )
hemis = results.find_all("div", class_="item")

# +
for hemi in hemis:
    title = hemi.find("h3").text
    img_link = hemi.find("a")["href"]
    usgs_img_link = "https://astrogeology.usgs.gov" + img_link    
    browser.visit(usgs_img_link)
    html = browser.html
    soup = BeautifulSoup(html, "html.parser")
    downloads = soup.find("div", class_="downloads")
    usgs_img_url = downloads.find("a")["href"]
    mars_hemi.append({"title": title, "img_url": usgs_img_url})

mars_hemi

StarcoderdataJupyterScriptsDedupFiltered