<jupyter_start><jupyter_text>Mission to Mars<jupyter_code>import numpy as np
import pandas as pd
from splinter import Browser
from bs4 import BeautifulSoup as bs
import time
import requests
import re<jupyter_output><empty_output><jupyter_text>NASA Mars News<jupyter_code>!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)
time.sleep(3)
html = browser.html
soup = bs(html, 'html.parser')
slides = soup.find_all('li', class_='slide')
content_title = slides[0].find('div', class_ = 'content_title')
news_title = content_title.text.strip()
article_teaser_body = slides[0].find('div', class_ = 'article_teaser_body')
news_p = article_teaser_body.text.strip()
print("Title: ",news_title)
print("Paragraph: ",news_p)<jupyter_output>Title:  NASA's MAVEN Observes Martian Night Sky Pulsing in Ultraviolet Light
Paragraph:  Vast areas of the Martian night sky pulse in ultraviolet light, according to images from NASA’s MAVEN spacecraft. The results are being used to illuminate complex circulation patterns in the Martian atmosphere.<jupyter_text>JPL Mars Space Images<jupyter_code># url = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
base_url = 'https://www.jpl.nasa.gov'
url = base_url + '/spaceimages/?search=&category=Mars'
browser.visit(url)
time.sleep(3)
html = browser.html
soup = bs(html, 'html.parser')
image_url=soup.find("a", class_ = "button fancybox")["data-fancybox-href"]
featured_image_url = base_url + image_url
print(featured_image_url)<jupyter_output>https://www.jpl.nasa.gov/spaceimages/images/mediumsize/PIA19346_ip.jpg<jupyter_text>Mars Weather<jupyter_code>url = 'https://twitter.com/marswxreport?lang=en'
browser.visit(url)
time.sleep(3)
weather_html = browser.html
soup = bs(weather_html, "html.parser")
mars_tweets = [soup.find_all('p', class_="TweetTextSize"), soup.find_all('span', class_="css-901oao css-16my406 r-1qd0xha r-ad9z0x r-bcqeeo r-qvutc0")]
for tweets in mars_tweets:
    mars_tweet = tweets
for tweet in mars_tweet:
    if 'InSight' in tweet.text:
        mars_weather = tweet.text
        if tweet.a in tweet:
            mars_weather = mars_weather.strip(tweet.a.text)
        break
print(mars_weather)<jupyter_output>InSight sol 607 (2020-08-11) low -93.1ºC (-135.6ºF) high -18.9ºC (-2.1ºF)
winds from the WNW at 8.2 m/s (18.4 mph) gusting to 21.4 m/s (47.8 mph)
pressure at 7.90 hPa<jupyter_text>Mars Facts<jupyter_code>url = 'https://space-facts.com/mars/'
tables = pd.read_html(url)
tables
facts_df = tables[0]
facts_df.columns = ['Fact', 'Value']
facts_df['Fact'] = facts_df['Fact'].str.replace(':', '')
facts_df
facts_df = tables[0]
facts_df.columns = ['Fact', 'Value']
facts_df['Fact'] = facts_df['Fact'].str.replace(':', '')
facts_df
facts_html = facts_df.to_html()

print(facts_html)<jupyter_output><table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Fact</th>
      <th>Value</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>Equatorial Diameter</td>
      <td>6,792 km</td>
    </tr>
    <tr>
      <th>1</th>
      <td>Polar Diameter</td>
      <td>6,752 km</td>
    </tr>
    <tr>
      <th>2</th>
      <td>Mass</td>
      <td>6.39 × 10^23 kg (0.11 Earths)</td>
    </tr>
    <tr>
      <th>3</th>
      <td>Moons</td>
      <td>2 (Phobos &amp; Deimos)</td>
    </tr>
    <tr>
      <th>4</th>
      <td>Orbit Distance</td>
      <td>227,943,824 km (1.38 AU)</td>
    </tr>
    <tr>
      <th>5</th>
      <td>Orbit Period</td>
      <td>687 days (1.9 years)</td>
    </tr>
    <tr>
      <th>6</th>
      <td>Surface Temperature</td>
      <td>-87 to -5 °C</td>
    </tr>
    <tr>
      <th>7</th>
      <td>First Record</td>
      <td>2nd millennium BC</td>
    </tr>
    <tr>
      <th>8</th>
      <td>Recorded [...]<jupyter_text>Mars Hemispheres<jupyter_code>base_url = 'https://astrogeology.usgs.gov'
url = base_url + '/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'
browser.visit(url)
html = browser.html
soup = bs(html, 'html.parser')
items = soup.find_all('div', class_='item')
urls = []
titles = []
for item in items:
    urls.append(base_url + item.find('a')['href'])
    titles.append(item.find('h3').text.strip())
print(urls)
titles
browser.visit(urls[0])
html = browser.html
soup = bs(html, 'html.parser')
oneurl = base_url+soup.find('img',class_='wide-image')['src']
oneurl
img_urls = []
for oneurl in urls:
    browser.visit(oneurl)
    html = browser.html
    soup = bs(html, 'html.parser')
#     savetofile(textfilename,soup.prettify())
    oneurl = base_url+soup.find('img',class_='wide-image')['src']
    img_urls.append(oneurl)
    
img_urls
hemisphere_image_urls = []

for i in range(len(titles)):
    hemisphere_image_urls.append({'title':titles[i],'img_url':img_urls[i]})

hemisphere_image_urls
for i in range(len(hemisphere_image_urls)):
    print(hemisphere_image_urls[i]['title'])
    print(hemisphere_image_urls[i]['img_url'] + '\n')<jupyter_output>Cerberus Hemisphere Enhanced
https://astrogeology.usgs.gov/cache/images/f5e372a36edfa389625da6d0cc25d905_cerberus_enhanced.tif_full.jpg

Schiaparelli Hemisphere Enhanced
https://astrogeology.usgs.gov/cache/images/3778f7b43bbbc89d6e3cfabb3613ba93_schiaparelli_enhanced.tif_full.jpg

Syrtis Major Hemisphere Enhanced
https://astrogeology.usgs.gov/cache/images/555e6403a6ddd7ba16ddb0e471cadcf7_syrtis_major_enhanced.tif_full.jpg

Valles Marineris Hemisphere Enhanced
https://astrogeology.usgs.gov/cache/images/b3c7c6c9138f57b4756be9b9c43e3a48_valles_marineris_enhanced.tif_full.jpg
{'fraction_non_alphanumeric': 0.15695621468926554, 'fraction_numerical': 0.03336864406779661, 'mean_word_length': 4.49466537342386, 'pattern_counts': {'":': 0, '<': 100, '<?xml version=': 0, '>': 100, 'https://': 11, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, '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': '359567', 'license': 'ADSL', 'n_tokens_mistral': 2391, 'n_tokens_neox': 2249, 'n_words': 391, 'path': 'Missions_to_Mars/mssion_to_mars.ipynb', 'repo_name': 'ermiasgelaye/web-scraping-challenge', 'size': '5664'}