<jupyter_start><jupyter_text>Visiting the Nasa Mars News Site<jupyter_code>#visit the nasa mars site
url = 'https://mars.nasa.gov/news/'
browser.visit(url)

#can create delay for loading web page if wanted
#browser.is_element_present_by_css("ul.item_list li.slide", wait_time=1)
#convert the browser.html to a soup object
html = browser.html
mars_news_soup = BeautifulSoup(html, 'html.parser')

slide_elem = mars_news_soup.select_one('ul.item_list li.slide')
slide_elem.find("div", class_="content_title")
#Using parent element to find the first a tag and it to the variable "news_title"
news_title = slide_elem.find("div", class_="content_title").get_text()
news_title
#Use the parent element to find the text in the paragraph tag
news_headline = slide_elem.find("div", class_="article_teaser_body").get_text()
news_headline<jupyter_output><empty_output><jupyter_text>JPL SPACE IMAGES - FEATURED IMAGE<jupyter_code>#visit URL
url = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
browser.visit(url)
#Find and click on the full image button
full_image_elem = browser.find_by_id('full_image')
full_image_elem.click()
#Finding the more info button (the first one doesn't work, but by running both one of them can find the 'more info' button)
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()
#parsing the new html site we passed onto by clicking the more info button
html = browser.html
img_soup = BeautifulSoup(html, 'html.parser')
#find the images source url
img_src_url = img_soup.select_one('figure.lede a img').get('src')
img_src_url
image_url = f'https://www.jpl.nasa.gov{img_src_url}'
image_url<jupyter_output><empty_output><jupyter_text>MARS WEATHER<jupyter_code>#Going to this url
url = 'https://twitter.com/marswxreport?lang=en'
browser.visit(url)
#parsing the html with BeautifulSoup
html = browser.html
weather_soup = BeautifulSoup(html, 'html.parser')
# finding a tweet with the data-name '<NAME>'
mars_weather_tweet = weather_soup.find('div', attrs={"class": "tweet", "data-name": "<NAME>"})
mars_weather_tweet
#getting the weather report text from the tweet
mars_weather = mars_weather_tweet.find('p', 'tweet-text').get_text()
mars_weather
#Going to the astreology url
url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'
browser.visit(url)
hemi_img_urls = []

#getting the list of all the links for hemisphere images
links = browser.find_by_css("a.product-item h3")

#looping through the links, clic on it and find the sample anchor and then return back
for i in range(len(links)):
    hemisphere = {}
    
    #have to find each link to avoid it being stale element exemption
    browser.find_by_css("a.product-item h3")[i].click()
    
    #finding the sample image anchor tag and take the href url
    sample_elem = browser.find_link_by_text('Sample').first
    hemisphere['img_url'] = sample_elem['href']
    
    #Get hemisphere title
    hemisphere['title'] = browser.find_by_css("h2.title").text
    
    #Appending the title and image links as an object to the hemi_img_urls list
    hemi_img_urls.append(hemisphere)
    
    #navigate back to the startingg url
    browser.back()
hemi_img_urls<jupyter_output><empty_output><jupyter_text>Mars Facts<jupyter_code>import pandas as pd
mars_facts_df = pd.read_html('http://space-facts.com/mars/')[0]
mars_facts_df.columns = ['description', 'value']
mars_facts_df.set_index('description', inplace=True)
mars_facts_df
mars_facts_df.to_html()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11145165784341042, 'fraction_numerical': 0.0022290331568682086, 'mean_word_length': 6.03921568627451, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 5, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '90434', 'license': 'ADSL', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1235, 'n_words': 313, 'path': 'mission_to_mars.ipynb', 'repo_name': 'tyleralev/-tyleralev-GT_Mars_Web_Scrapping_And_Document_Databases_HMWK_12', 'size': '3601'}