<jupyter_start><jupyter_text>Set the chrome browser<jupyter_code># https://splinter.readthedocs.io/en/latest/drivers/chrome.html
!which chromedriver
executable_path = {'executable_path': '/usr/local/bin/chromedriver'}
browser = Browser('chrome', **executable_path, headless=False)<jupyter_output><empty_output><jupyter_text>NASA Mars News<jupyter_code>url = 'https://mars.nasa.gov/news/'
browser.visit(url)
html = browser.html
soup = BeautifulSoup(html, 'html.parser')
slides = soup.find_all('li', class_='slide')

# capture the first result
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(f"Title:\n{news_title}\n")
print(f"Paragraph Text:\n{news_p}")<jupyter_output>Title:
MOXIE Could Help Future Rockets Launch Off Mars

Paragraph Text:
NASA's Perseverance rover carries a device to convert Martian air into oxygen that, if produced on a larger scale, could be used not just for breathing, but also for fuel.<jupyter_text>JPL Mars Space Images - Featured Image<jupyter_code>base_url = "https://www.jpl.nasa.gov"
url = base_url + "/spaceimages/?search=&category=Mars"
browser.visit(url)
html = browser.html
soup = BeautifulSoup(html, 'html.parser')
href = soup.find("a", class_ = "button fancybox")["data-fancybox-href"]
featured_image_url = base_url + href
print(featured_image_url)<jupyter_output>https://www.jpl.nasa.gov/spaceimages/images/mediumsize/PIA17900_ip.jpg<jupyter_text>Mars Facts<jupyter_code>## move Mars Facts table into dataframe
url = "https://space-facts.com/mars/"
tables = pd.read_html(url)
table_df = tables[0]
table_df.columns = ['Fact', 'Value']
table_df["Fact"]= table_df["Fact"].str.replace(":","")

## convert dataframe into html table string
table_html = table_df.to_html()
print(table_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 = BeautifulSoup(html, 'html.parser')
items = soup.find_all("div", class_ = "item")

# capture the url for each of the results
titles = []
urls = []
for item in items:
    titles.append(item.find("h3").text.strip())
    urls.append(base_url + item.find("a")["href"])

# dig into the class downloads and search for the second item in list for Original TIF file
img_url = []
for url in urls:
    browser.visit(url)
    html = browser.html
    soup = BeautifulSoup(html, 'html.parser')
    item = soup.find("div",class_='downloads')
    img_url.append(item.find_all("li")[1].find("a")["href"])

# move img_url and titles into hemisphere_image_urls
hemisphere_image_urls = []
for i in range(len(titles)):
    hemisphere_image_urls.append({'title':titles[i],'img_url':img_url[i]})

hemisphere_image_urls<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1680990899898888, 'fraction_numerical': 0.015672396359959553, 'mean_word_length': 4.060102301790281, 'pattern_counts': {'":': 1, '<': 98, '<?xml version=': 0, '>': 98, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '208463', 'license': 'ADSL', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1505, 'n_words': 295, 'path': 'Missions_to_Mars/mission_to_mars.ipynb', 'repo_name': 'cyrusauyeungc/web-scraping-challenge', 'size': '3956'}