<jupyter_start><jupyter_text>NASA Mars News<jupyter_code># URL of page to be scraped
url = 'https://mars.nasa.gov/news/'
# Retrieve page with the requests module
response = requests.get(url)
# Create BeautifulSoup object; parse with 'html.parser'
soup = bs(response.text, 'html.parser')
# Examine the results, then determine element that contains sought info
print(soup.prettify())
# Extract title text
news_items = soup.find_all(class_='slide')
news_title = news_items[0].find(class_='content_title').text
print (news_title)
# Print paragraph texts
news_p = news_items[0].find(class_='rollover_description_inner').text
print (news_p)<jupyter_output>NASA is investing in technology concepts, including several from JPL, that may one day be used for future space exploration missions.<jupyter_text>JPL Mars Space Images - Featured Image<jupyter_code>!which chromedriver
executable_path = {'executable_path': '/usr/local/bin/chromedriver'}
browser = Browser('chrome', **executable_path, headless=False)
url = 'https://www.jpl.nasa.gov/spaceimages/?search=&category=Mars'
browser.visit(url)
html = browser.html
soup = bs(html, 'html.parser')
articles = soup.find_all('article', class_='carousel_item')
for article in articles:
    footer = article.find('footer')
    featured_image_url = 'https://www.jpl.nasa.gov' + footer.a['data-fancybox-href']
    print (featured_image_url)<jupyter_output>https://www.jpl.nasa.gov/spaceimages/images/mediumsize/PIA16101_ip.jpg<jupyter_text>Mars Weather<jupyter_code># URL of page to be scraped
url = 'https://twitter.com/marswxreport?lang=en'

# Retrieve page with the requests module
response = requests.get(url)
# Create BeautifulSoup object; parse with 'lxml'
soup = bs(response.text, 'lxml')
results = soup.find_all('p', class_='TweetTextSize TweetTextSize--normal js-tweet-text tweet-text')
weather = []
for result in results:
    if "Sol" in result.text:
        weather.append(result.text)
mars_weather = weather[0]
print (mars_weather)<jupyter_output>Sol 2051 (May 14, 2018), Sunny, high 1C/33F, low -71C/-95F, pressure at 7.39 hPa, daylight 05:21-17:20<jupyter_text>Mars Facts<jupyter_code>url = 'http://space-facts.com/mars/'
tables = pd.read_html(url)
tables
df = tables[0]
df.columns = ["Description", "Value"]
df.set_index("Description", inplace=True)
df
html_table = df.to_html()
html_table.replace('\n', '')
df.to_html('templates/table.html')
!open table.html<jupyter_output><empty_output><jupyter_text>Mars Hemisperes<jupyter_code>executable_path = {'executable_path': '/usr/local/bin/chromedriver'}
browser = Browser('chrome', **executable_path, headless=False)
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')
results = soup.find_all(class_='item')
hemisphere_image_urls = []
for result in results:
    title = result.find('h3').text
    browser.visit('https://astrogeology.usgs.gov/' + result.find('a')['href'])
    html = browser.html
    soup = bs(html, 'html.parser')
    response = soup.find_all(class_='downloads')[0]
    img_url = (response.a)['href']
    hemisphere_image_urls.append({"title":title, "img_url":img_url})
print (hemisphere_image_urls)<jupyter_output>[{'title': 'Cerberus Hemisphere Enhanced', 'img_url': 'http://astropedia.astrogeology.usgs.gov/download/Mars/Viking/cerberus_enhanced.tif/full.jpg'}, {'title': 'Schiaparelli Hemisphere Enhanced', 'img_url': 'http://astropedia.astrogeology.usgs.gov/download/Mars/Viking/schiaparelli_enhanced.tif/full.jpg'}, {'title': 'Syrtis Major Hemisphere Enhanced', 'img_url': 'http://astropedia.astrogeology.usgs.gov/download/Mars/Viking/syrtis_major_enhanced.tif/full.jpg'}, {'title': 'Valles Marineris Hemisphere Enhanced', 'img_url': 'http://astropedia.astrogeology.usgs.gov/download/Mars/Viking/valles_marineris_enhanced.tif/full.jpg'}]
{'fraction_non_alphanumeric': 0.14813857290589452, 'fraction_numerical': 0.010599793174767322, 'mean_word_length': 6.411877394636015, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 7, 'lorem ipsum': 0, 'www.': 3, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '346889', 'license': 'ADSL', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1364, 'n_words': 254, 'path': 'mission_to_mars.ipynb', 'repo_name': 'jjj3035/web_scraping', 'size': '3868'}