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

from splinter import Browser
from bs4 import BeautifulSoup
import pandas as pd

# +
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
# -

from selenium import webdriver
executable_path = {'executable_path': r'C:\Users\jasmi\.wdm\drivers\chromedriver\83.0.4103.39\win32\chromedriver.exe'}

driver = webdriver.Chrome(r"C:\Users\jasmi\.wdm\drivers\chromedriver\83.0.4103.39\win32\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')

# +
news_title = soup.find_all('div', class_='content_title')[1].text
print(news_title)

news_p = soup.find_all('div', class_='article_teaser_body')[0].text
print(news_p)
# -

browser = Browser('chrome', **executable_path, headless = False)

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

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

# +
image_url = soup.find_all('article', class_='carousel_item')[0]['style'][24:-3]

featured_image_url = 'https://www.jpl.nasa.gov/' + image_url
print(featured_image_url)
# -

url = "https://twitter.com/marswxreport?lang=en"
browser.visit(url)

tw = browser.find_by_css("section div [lang='en']")[0].html
BeautifulSoup(tw, 'html.parser').text

[BeautifulSoup(tw.html, 'html.parser').text  for tw in browser.find_by_css("section div [lang='en']")]

??browser.find_by

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

mars_weather = soup.article.find_all('div', attrs = {"lang" : "en"})
print(mars_weather)

mars_weather = soup.article.find_all('span')[4].text
print(mars_weather)

# +
Mars_facts_df = pd.read_html("https://space-facts.com/mars/")[0]

Mars_facts_df.rename(columns={0: "description", 1: "value"}, inplace=True)
Mars_facts_df.set_index('description', inplace=True)
Mars_facts_df
# -

Mars_facts_table = Mars_facts_df.to_html()
print(Mars_facts_table)

url = "https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars"
browser.visit(url)

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

# +
hemisphere_image_urls = []

for peice in soup.find_all('div', class_="description"):
    title_list = peice.h3.text.split(" ")
    title_list.pop()
    title = " ".join(title_list)
    hemisphere_image_urls.append({'title': f"{title}"})
    print(title)
# -

for x in range(len(hemisphere_image_urls)):
    url = "https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars"
    browser.visit(url)
    html = browser.html
    soup = BeautifulSoup(html, 'html.parser')
    browser.click_link_by_partial_text(f"{hemisphere_image_urls[x]['title']}")
    html = browser.html
    soup = BeautifulSoup(html, 'html.parser')
    hemisphere_image_urls[x]['img_url'] = soup.find('div', class_="downloads").find_all('a')[0]['href']
print(hemisphere_image_urls)











StarcoderdataJupyterScriptsDedupFiltered