<jupyter_start><jupyter_text>Featured Images<jupyter_code># Visit URL
url = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
browser.visit(url)
# Find and click the full image button
full_image_elem = browser.find_by_id('full_image')
full_image_elem.click()
# Find the more info button and click that
browser.is_element_present_by_text('more info', wait_time=1)
more_info_elem = browser.links.find_by_partial_text('more info')
more_info_elem.click()
# Parse the resulting html with soup
html = browser.html
img_soup = soup(html, 'html.parser')
# Find the relative image url
img_url_rel = img_soup.select_one('figure.lede a img').get("src")
img_url_rel
# Use the base URL to create an absolute URL
img_url = f'https://www.jpl.nasa.gov{img_url_rel}'
img_url
# tables into pandas
# pull only first table it finds
df = pd.read_html('http://space-facts.com/mars/')[0]
df.columns=['description', 'value']
df.set_index('description', inplace=True)
df
browser.quit()
# Import Splinter and BeautifulSoup
from splinter import Browser
from bs4 import BeautifulSoup
import pandas as pd
# Windows users
executable_path = {'executable_path': 'chromedriver.exe'}
browser = Browser('chrome', **executable_path, headless=False)# Visit the Quotes to Scrape site
# Visit the mars nasa news site
url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'
browser.visit(url)
# Optional delay for loading the page
browser.is_element_present_by_css("div.collapsible.results", wait_time=1)
html = browser.html
news_soup = BeautifulSoup(html, 'html.parser')

news_soup
results = news_soup.find('div', class_='results')
results
all_hems = news_soup.find_all('div', class_='item')
all_hems
len(all_hems)
info = []

for hem in all_hems:
    d = {}
    d["title"] = hem.h3.text
    d["img_url"] = f"https://astrogeology.usgs.gov{hem.a['href']}"
    d["thumb"] = f"https://astrogeology.usgs.gov{hem.img['src']}"
    d["description"] = hem.p.text
    info.append(d)
#     d["thumb"] = hem.img['src']
#     d["description"] = hem.p.text
#     print(hem.h3.text)
#     print(hem.a['href'])
#     print(hem.img['src'])
#     print(hem.img['alt'])
#     print(hem.p.text)
   
info
    
len(info)
for item in info:
    print(item)
browser.quit()
import pandas as pd
df = pd.DataFrame(info)
df
df['img_url']
print(info[0]['img_url'])
print(info[1]['img_url'])
res = [sub['img_url'] for sub in info]
res
df.to_html(classes="table table-hemisphere")
url = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
print(f'Opening URL:{url}')
browser.visit(url)

# Find and click the full image button
full_image_elem = browser.find_by_id('full_image')
full_image_elem.click()

# Find the more info button and click that
browser.is_element_present_by_text('more info', wait_time=1)
more_info_elem = browser.find_link_by_partial_text('more info')
more_info_elem.click()

# Parse the resulting html with soup
html = browser.html
img_soup = soup(html, 'html.parser')

try:
    # find the relative image url
    img_url_rel = img_soup.select_one('figure.lede a img').get("src")
except AttributeError:
    print("Error")

# Use the base url to create an absolute url
img_url = f'https://www.jpl.nasa.gov{img_url_rel}'
img_url<jupyter_output>Opening URL:https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars
{'fraction_non_alphanumeric': 0.1437613019891501, 'fraction_numerical': 0.003315250150693189, 'mean_word_length': 5.482421875, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 8, 'lorem ipsum': 0, 'www.': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '499332', 'license': 'MIT', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1190, 'n_words': 263, 'path': 'Mission_to_Mars.ipynb', 'repo_name': 'ltcastillo/Mission-to-Mars', 'size': '3318'}