<jupyter_start><jupyter_text>Visit the NASA Mars News Site<jupyter_code># Visit the mars nasa news site
url = 'https://redplanetscience.com/'
browser.visit(url)
#save the browser html and clean it using beautiful soup
html = browser.html
news_soup = BeautifulSoup(html, 'html.parser')
news_soup
first_article=news_soup.find_all("div", class_="list_text")[0]


news_title = first_article.find("div", class_="content_title").text
news_title
news_p = first_article.find("div", class_="article_teaser_body").text
news_p<jupyter_output><empty_output><jupyter_text>JPL Space Images Featured Image<jupyter_code># Visit URL
url = 'https://spaceimages-mars.com'
browser.visit(url)
spaceimageshtml=browser.html
#Create a BeautifulSoup object
spaceimages_soup = BeautifulSoup(spaceimageshtml, 'html.parser')
spaceimages_soup
relative_image_url_scraped_from_site = spaceimages_soup.find("a", class_="fancybox-thumbs")["href"]
relative_image_url_scraped_from_site

# Use the base url to create an absolute url
img_url = f'https://spaceimages-mars.com/{relative_image_url_scraped_from_site}'
img_url<jupyter_output><empty_output><jupyter_text>Mars Facts<jupyter_code># WHEN USING THE pd.read_html function, WHY DO YOU THINK WE HAD TO GET THE ZERO-th INDEX?
# HINT: Peak around the website below to perhaps understand why...
mars_facts_df = pd.read_html('https://galaxyfacts-mars.com')[0]
mars_facts_df
# WRITE YOUR OWN CODE TO CLEAN THIS DATAFRAME
mars_facts_df.reset_index(inplace=True)
mars_facts_df.columns=["ID", "Mars-earth Comparison", "Mars", "Earth"]
mars_facts_df
clean_df = mars_facts_df.drop(mars_facts_df.index [ [ 0] ])
clean_df 
# CONVERT TO HTML :)
# YAY PAND
mars_facts = mars_facts_df.to_html()
mars_facts<jupyter_output><empty_output><jupyter_text>D1: Scrape High-Resolution Mars’ Hemisphere Images and Titles  Hemispheres<jupyter_code>url = 'https://marshemispheres.com/'
browser.visit(url)
#save the browser html and clean it using beautiful soup
hemisphereshtml = browser.html
hemispheres_soup = BeautifulSoup(hemisphereshtml, 'html.parser')
hemispheres_soup
hemispheressoup_reduced =hemispheres_soup.find("div", class_="collapsible results")
hemispheressoup_reduced
pre_hemilist=hemispheressoup_reduced.find_all("a", class_="itemLink product-item")
pre_hemilist
hemi_tags =[]
for i in range(0,len(pre_hemilist)):
    if i%2!=0:
        hemi_tags.append(f'{url}{pre_hemilist[i]["href"]}')

hemi_tags
# Write a for loop to retrieve the image urls and titles for each hemisphere in the url above.
# Create a list to hold the images and titles.
hemisphere_image_urls = []

for tag in hemi_tags:
    browser.visit(tag)
# Print the list that holds the dictionary of each image url and title.
hemi_tags
# Finally, close the Google Chrome window...
browser.quit()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10526315789473684, 'fraction_numerical': 0.002506265664160401, 'mean_word_length': 7.07514450867052, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '235807', 'license': 'ADSL', 'n_tokens_mistral': 1019, 'n_tokens_neox': 985, 'n_words': 230, 'path': 'Mission_to_mars/mission_to_mars.ipynb', 'repo_name': 'Dozie14/web-scraping-challenge', 'size': '2793'}