<jupyter_start><jupyter_text>Step One  NASA Mars News<jupyter_code>#using  chromedriver and browser method
#setup and fire up browser task 1 
executable_path = {'executable_path': 'chromedriver'}
browser = Browser('chrome', **executable_path, headless=False)

#visit URL
url = 'https://mars.nasa.gov/news/'
browser.visit(url)

time.sleep(2)

html = browser.html
soup = bs(html, 'html.parser')

#find relevant class and store in a list 
item_list = soup.find_all('li', class_ = 'slide')

#loop and strip the html
titles = []
descriptions = []
for data in item_list:
    
    title = data.find('h3').text
    titles.append(title)
    
    description = data.find('a').text
    descriptions.append(description)

# Close the browser after scraping
browser.quit()
titles[0]
#inspecting final results
print("\n-------   Titles    ----------\n")
print(titles[:2])
print("\n-------   Descriptions    ----------\n")
print(descriptions[:2])<jupyter_output>-------   Titles    ----------

['Mars Is Getting a New Robotic Meteorologist', "NASA's Curiosity Takes Selfie With 'Mary Anning' on the Red Planet"]

-------   Descriptions    ----------

["Sensors on NASA's Perseverance will help prepare for future human exploration by taking weather measurements and studying dust particles.Mars Is Getting a New Robotic Meteorologist", "The Mars rover has drilled three samples of rock in this clay-enriched region since arriving in July.NASA's Curiosity Takes Selfie With 'Mary Anning' on the Red Planet"]<jupyter_text>JPL Mars Space Images - Featured Image<jupyter_code>#using request method 
#initial URL
url = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
response = requests.get(url)

#soup object: html doc
soup = bs(response.text, 'html.parser')

#url inspection and finding the image's parent class
all_images = soup.find_all('a', class_ = 'fancybox')

#looping through each image
imglinks_list = []
for img_html in all_images:
    
    #image link
    img_link = img_html['data-fancybox-href']
    
    #full url concant and append
    featured_image_url = 'https://www.jpl.nasa.gov/spaceimages/' + img_link
    imglinks_list.append(featured_image_url)

imglinks_list[:5]
#using request method 
#initial URL
url = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
response = requests.get(url)

#soup object: html doc
soup = bs(response.text, 'html.parser')

#url inspection and finding the image's parent class
img_src = soup.footer.a["data-fancybox-href"]

featured_img = "https://www.jpl.nasa.gov/" + img_src
featured_img<jupyter_output><empty_output><jupyter_text>Mars Facts<jupyter_code>url = 'https://space-facts.com/mars/'
df = pd.read_html(url)
mars_table = df[0]
mars_table = mars_table.rename({0: "", 1: "Data"}, axis =1).set_index("")
mars_table
#export as a html file
mars_table.to_html("mars_facts.html")<jupyter_output><empty_output><jupyter_text>Mars Hemispheres<jupyter_code>#using  chromedriver and browser method
#setup and fire up browser task 1 
executable_path = {'executable_path': 'chromedriver'}
browser = Browser('chrome', **executable_path, headless=False)

#visit URL
url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'
browser.visit(url)

html = browser.html
soup = bs(html, 'html.parser')

#all items where the links are stored
items = soup.find_all('div', class_ = 'item')

home_url = 'https://astrogeology.usgs.<EMAIL>' 

#here I will store dictionaries for each item
links_list = []

#looping through each item
for item in items:
    
    #initialising empty dictionary to store the links of each image
    hemishpere_data = {}
    
    #dictionary key: 'title' ; value-pair: item title
    hemishpere_data['title'] = item.find('h3').text.strip('Enhanced').strip()
    
    #find image link, create new URL, request and create soup object
    img_link = item.find('a')['href']
    new_url = home_url + img_link
    response = requests.get(new_url)
    soup = bs(response.text, 'html.parser')
   
    #find full image link 
    full_size_img = soup.find_all('div', class_ = 'downloads')[0].find('li').find('a')['href']
    
    #dictionary key for link
    hemishpere_data['img_url'] = full_size_img
    
    #appending dictionary to the list 
    links_list.append(hemishpere_data)

# Close the browser after scraping
browser.quit()
links_list<jupyter_output><empty_output><jupyter_text>All scrapes complete   Compiling all scrapes into 1 dictionary<jupyter_code>mars_data = {"news_title": titles[0],
                "mars_news":descriptions[0],
                "img_links": featured_img,
                "hemispheres": links_list
                 }
mars_data<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13156770610850063, 'fraction_numerical': 0.004058094831268688, 'mean_word_length': 4.186046511627907, 'pattern_counts': {'":': 4, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '54980', 'license': 'ADSL', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1549, 'n_words': 399, 'path': 'Missions_to_Mars/mission_to_mars.ipynb', 'repo_name': 'ZGallo/web-scraping-challenge', 'size': '4678'}