<jupyter_start><jupyter_text>Import libraries<jupyter_code>import requests
import pandas
from splinter import Browser
from bs4 import BeautifulSoup
from webdriver_manager.chrome import ChromeDriverManager
import pandas as pd
#! pip install Flask-PyMongo
executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=False)
url = 'https://redplanetscience.com/'
browser.visit(url)
# HTML object
html = browser.html
# Parse HTML with Beautiful Soup
soup = BeautifulSoup(html, 'html.parser')<jupyter_output><empty_output><jupyter_text>NASA Mars News<jupyter_code>text = soup.select_one("div.list_text")
text

#Scrape and collect the latest News Title and Paragraph Text
news_title=text.find("div", class_="content_title").get_text()
news_p =text.find("div", class_="article_teaser_body").get_text()
news_date=text.find("div", class_="list_date").get_text()
print('---------------')
print(news_date)
print(news_title)
print(news_p)
img = soup.select_one("div.list_image")
img
news_img=img.find("img").get('src')
print('---------------')
print(news_img)<jupyter_output>---------------
https://mars.nasa.gov/system/news_items/list_view_images/8520_PIA23466-226.jpg<jupyter_text>JPL Mars Space Images - Featured Image<jupyter_code>executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=False)
url = "https://spaceimages-mars.com"
browser.visit(url)

browser.find_by_css('.fancybox-thumbs').click() 

# HTML object
html = browser.html
# Parse HTML with Beautiful Soup
soup = BeautifulSoup(html, 'html.parser')
 
partial_img_url=soup.select_one("img.fancybox-image" ).get("src")
partial_img_url
img_url = f"https://spaceimages-mars.com/{partial_img_url}"
print(img_url)<jupyter_output>https://spaceimages-mars.com/image/featured/mars3.jpg<jupyter_text>Mars Facts<jupyter_code>url = 'https://galaxyfacts-mars.com/'
tables = pd.read_html(url)
df=tables[0]
df.columns=df.iloc[0]
df.drop(0,inplace=True)
df.head()

df.to_html('table.html')<jupyter_output><empty_output><jupyter_text>Mars Hemispheres<jupyter_code>executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=False)
url="https://marshemispheres.com/"
browser.visit(url)
hemisphere_image_urls = []



for item in range(4):
    hemisphere = {}
    
    
    browser.find_by_css("a.product-item h3")[item].click()
    
    
    sample_element = browser.find_link_by_text("Sample").first
    hemisphere["img_url"] = sample_element["href"]
    
    
    hemisphere["title"] = browser.find_by_css("h2.title").text
    
    
    hemisphere_image_urls.append(hemisphere)
    
    
    browser.back()


hemisphere_image_urls<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15464285714285714, 'fraction_numerical': 0.007142857142857143, 'mean_word_length': 5.967661691542289, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 7, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '428325', 'license': 'ADSL', 'n_tokens_mistral': 1007, 'n_tokens_neox': 982, 'n_words': 146, 'path': 'Missions_to_Mars/mission_to_mars.ipynb', 'repo_name': 'lalesafarzade/web-scraping-challenge', 'size': '2800'}