<jupyter_start><jupyter_text>Featured Images<jupyter_code># trying to automate splinter into getting the full sized featured image

# visiting JPL images and retrieving featured images

url = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
browser.visit(url)
# getting to featured image
full_image_elem = browser.find_by_id('full_image')

full_image_elem.click()

# more info is found, checked, stored as reference, and accessed with click

browser.is_element_present_by_text('more info', wait_time=1)
# searches for element with provided text, returns a bool

more_info_elem = browser.links.find_by_partial_text('more info')
# uses 'more info' to find associated link

more_info_elem.click()
# parsing full image html with soupy to scrape full-size image url

parse_html = browser.html

full_img_soup = soupy(parse_html, 'html.parser' )

# finding the latest image every time, instead of the current image present, to avoid relying on the URL

latest_image_full = full_img_soup.select_one('figure.lede a img').get("src")

latest_imgurl = f"https://www.jpl.nasa.gov{latest_image_full}"

latest_imgurl #resulted link will always be changing in regards to the featured image
# mars hemis with names and url links

url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'

browser.visit(url)

browser.is_element_present_by_text('Cerberus Hemisphere Enhanced', wait_time=1)

hemi1_click1 = browser.links.find_by_partial_text('Cerberus Hemisphere Enhanced')
# # uses 'more info' to find associated link

hemi1_click1

# hemi1_click1.click()

# parse_html = browser.html

# hemi1_parse_html = soupy(parse_html, 'html.parser' )

# hemi1_url = hemi1_parse_html.select_one('ul li a').get("href")

# hemi1_url
hemis_search_list = ['Cerberus Hemisphere Enhanced',
                     'Schiaparelli Hemisphere Enhanced',
                     'Syrtis Major Hemisphere Enhanced',
                     'Valles Marineris Hemisphere Enhanced']

hemis_search_list[0]

names_n_url = []

Hemisphere = "Hemisphere"

URL = "URL"

for x in range(len(hemis_search_list)):
    
    url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'

    browser.visit(url)

    browser.is_element_present_by_text((f'{hemis_search_list[x]}'), wait_time=2)

    hemi_click = browser.links.find_by_partial_text(f'{hemis_search_list[x]}')

    hemi_click.click()

    parse_html = browser.html

    hemi_parse_html = soupy(parse_html, 'html.parser' )

    hemi_img_url = hemi_parse_html.select_one('ul li a').get("href")

    names_n_url.append({Hemisphere:hemis_search_list[x],URL:hemi_img_url})

df_hemi_urls = pd.DataFrame.from_dict(names_n_url, orient='columns')

df_hemi_urls.set_index('Hemisphere', inplace=True)

pd.set_option('display.max_colwidth', -1)

df_hemi_urls


df_html = df_hemi_urls.to_html(
    render_links=True,
    escape=False,
)

df_html
names_n_url.items()
# df = pd.DataFrame(names_n_url, columns=['Hemispheres', 'Links'])

new_df = pd.DataFrame.from_dict(names_n_url, orient='columns')

new_df.set_index('Hemisphere', inplace=True) # set column index
# new_dfpd.DataFrame.from_dict(data, orient='coloumns')

pd.set_option('display.max_colwidth', -1)

new_df

df = pd.Series(names_n_url)
# df.columns = ['Hemispheres', 'Links'] # adds column names
# df.set_index('Hemispheres', inplace=True) # set column index

df2 = pd.DataFrame(df)

df2
url_list = []

url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'

browser.visit(url)

# browser.is_element_present_by_text('Cerberus Hemisphere Enhanced', wait_time=1)

parse_html = browser.html

url_collect = soupy(parse_html, 'html.parser' )

url_collect.find_all_next('/search/map/Mars/Viking')

# url_collect.find_all('h3')

# url_collect.find('h3').text

# for get_url in url_list:
    
#     hemi_article_page = url_collect.select_one('div.description a').get("href")
# href_click1_list = []

# url_list_only = []

# href_click1 = url_collect.select('div.description a[href^="/search/map/Mars/Viking"]')

# browser.click_link_by_href(href_click1)

# for x in range(1,4):
    
#     browser.click_link_by_href(href_click1)
        
#     name = clean.get("href")
    
# #     browser.links.find_by_href(name)
    
#     href_click1_list.append(f"https://astrogeology.usgs.gov/{name}")
    
#     click_first = browser.links.find_by_href(name)
    
#     click_first.click()
    
#     parse_html = browser.html

#     link_collect = soupy(parse_html, 'html.parser' )
    
#     url_get = link_collect.select_one('ul li a').get("href")

#     url_list_only.append(url_get)
    
    
# href_click1_list

# href_click1_list[2].click

# browser.links.find_by_text(f"{href_click1_list[0]}").click()



    
    
# # 
#     for article_url in :
# #         use get_url to visit articl page
# #         get image_url









browser.click_link_by_href('/search/map/Mars/Viking/schiaparelli_enhanced')
# url_collect.select_one('div.description a').get("href")

# url_collect.find_all_next('div.description a')

href_click1 = url_collect.select('div.description a[href^="/search/map/Mars/Viking"]')

href_click1_list = []

for clean in href_click1:
    name = clean.get("href")
    
    browser
    
    href_click1_list.append(f"https://astrogeology.usgs.gov/{name}")
    

    
# href_click1_list[1].click()


# finding h3 since all hemis fall under that

url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'

browser.visit(url)

parse_html = browser.html

h3_soup = soupy(parse_html, 'html.parser' )

h3_tag = h3_soup.find_all('h3')

h3_tag

# hemi_names = {}

hemis_names = []

for clean in h3_tag:
    name = clean.text
    
    hemis_names.append(name)
    
    
hemis_names


# # h3_find = full_img_soup.find('div', class_='collapsible results')

# # h3_deeper = h3_find.find('div', class_='description')

# h3_hemi1 = h3_tags.select_one('div', class_='description')

# print(h3_hemi1)

# h3_tags = h3_find.find_all('a', class_='itemLink product-item')

# h3_tags

# h3_tags = h3_find.find_all('h3')<jupyter_output><empty_output><jupyter_text>Mars Facts<jupyter_code># using pd readHTML function to read an entire Mars facts html table

mars_df = pd.read_html('https://space-facts.com/mars/')[0]
# read_html pulls all tables in a given link turns into a df, [0] narrows down to first table

mars_df.columns = ['description','value'] # adds column names


mars_df.set_index('description', inplace=True) # set column index


mars_df

mars_df.to_html() #incase converting df back to html
browser.quit()
arr = ['apple', 'organe', 'heck', 'animal']

# # for x in range(len(arr)):
# #     for y in range(len(arr)):
# #         print(arr[x],arr[y])
        
# # [print(arr[x],arr[y]) for x in range(len(arr)) for y in range(len(y))]



# def fizzbuzz(x):
#     for x in range(1,101):
#         if (x % 3 | x % 5) == 0:
#             print('fizzbuzz')
#         elif x % 5 == 0:
#             print('buzz')
#         elif x % 3 == 0:
#             print('fizz')
#         else:
#             print(x)

# fizzbuzz(x)



def test_func():
    for x in range(len(arr)):
        for y in range(len(arr)):
            print(arr[x],arr[y])
    return len(arr), 3+5, url
    
            
            
test_func()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13168668122270744, 'fraction_numerical': 0.0113264192139738, 'mean_word_length': 4.135949544498949, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 9, 'lorem ipsum': 0, 'www.': 2, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '292345', 'license': 'MIT', 'n_tokens_mistral': 2795, 'n_tokens_neox': 2739, 'n_words': 492, 'path': 'Mars_Scraping/Mission_to_Mars.ipynb', 'repo_name': 'SiMewL8/Mission-To-Mars', 'size': '7328'}