<jupyter_start><jupyter_text>NASA Mars News<jupyter_code># Retrieve the parent divs for all articles

# results = soup.find_all('div', class_='content_title')
# results

news_title = soup.find('div', class_='content_title').find('a').text.strip()
p_news = soup.find('div', class_='rollover_description_inner').text.strip()


print(news_title)
print(p_news)

#CODE THAT GRABS ALL TITLES/HEADLINES

# titles = []
# # Loop through returned results
# for result in results:
#     # Access the thread's text content
#     title_text = result.a.text
# #     print(title_text)

#     titles.append(title_text)

# titles

# news_titles = []

# for title in titles:
#     news_titles.append(title.strip())

# print(news_titles)

# aResults = soup.find_all('div', class_='rollover_description_inner')
# aResults

# p = []
# # Loop through returned results
# for result in aResults:
#     p.append(result.text)

# news_p = []

# for text in p:
#     news_p.append(text.strip())
# print(news_p)<jupyter_output><empty_output><jupyter_text>JPL Mars Space Images - Featured Image<jupyter_code>featured_img_url = 'https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/index.html'

# # Retrieve page with the requests module
# response = requests.get(featured_img_url)
# # Create BeautifulSoup object; parse with 'html.parser'
# soup = BeautifulSoup(response.text, 'html.parser')

# featured_image = soup.find_all('a')



executable_path = {'executable_path': '/usr/local/bin/chromedriver'}
browser = Browser('chrome', **executable_path, headless=False)


browser.visit(featured_img_url)
html = browser.html
soup = BeautifulSoup(html, 'html.parser')
#search for the image link
featured_image = soup.find('a', class_='showimg fancybox-thumbs')
href = featured_image['href']
href


#set base url by dropping index.html from the featured image link
img_url = featured_img_url.replace('index.html', '')
#concatenating the two
print(img_url+href)<jupyter_output>https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/image/featured/mars3.jpg<jupyter_text>Mars Facts<jupyter_code>facts_url = 'https://space-facts.com/mars/'
response = requests.get(facts_url)
soup = BeautifulSoup(response.text)
#print(soup.prettify())
#Parse HTML Using Pandas

tables = pd.read_html(facts_url)
df = tables[0]
df
html_table = df.to_html()
html_table<jupyter_output><empty_output><jupyter_text>Mars Hemispheres<jupyter_code>executable_path = {'executable_path': '/usr/local/bin/chromedriver'}
browser = Browser('chrome', **executable_path, headless=False)
hemis_url = 'https://astrogeology.usgs.gov/search/results?q=hemisphere+enhanced&k1=target&v1=Mars'
browser.visit(hemis_url)

html = browser.html
soup = BeautifulSoup(html, 'html.parser')
aitems = soup.find_all('div', class_='item')
base_url = hemis_url.replace('/search/results?q=hemisphere+enhanced&k1=target&v1=Mars', '')
hemisphere_image_urls = []
for item in aitems:
    #find the title by going to the h3 tag
    title = item.find('h3').text
    #find the img ref in the href tag of an a tag with with itemLinkClass
    part_img_ref = item.find('a', class_='itemLink product-item')['href']
    #concantenate the base url with the part_img_ref and visit that new url
    browser.visit(base_url+part_img_ref)
    #html object of new page
    partial_img_html = browser.html
    #parsing html of new page
    soup = BeautifulSoup(partial_img_html, 'html.parser')
    #grabbing the full image path from the img tag/source attribute and concatenating with base url
    img_url = base_url+soup.find('img', class_='wide-image')['src']
    #appending final concatenated urls into the empty list in dict format
    hemisphere_image_urls.append({"Title": title, "img_url": img_url})


hemisphere_image_urls<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12830088023472927, 'fraction_numerical': 0.002667377967457989, 'mean_word_length': 5.567425569176883, 'pattern_counts': {'":': 2, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 4, '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': '404208', 'license': 'ADSL', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1305, 'n_words': 277, 'path': 'Mission_to_Mars/mission_to_mars.ipynb', 'repo_name': 'geofftm/web-scraping-challenge', 'size': '3749'}