<jupyter_start><jupyter_text>NASA Mars News<jupyter_code>url = 'https://mars.nasa.gov/news/?page=0&per_page=40&order=publish_date+desc%2Ccreated_at+desc&search=&category=19%2C165%2C184%2C204&blank_scope=Latest'
browser.visit(url)
# html = requests.get(url).text
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
print(soup.prettify())
title = soup.title.text
print(title) 
news_title_all = soup.find_all('div', class_='content_title')
# result = soup.find_all('title')


news_title_all

news_title = soup.find('div', class_='content_title')
# result = soup.find_all('title')


news_title
title= news_title.text
title

title.strip()
news_p_all = soup.find_all('div', class_='rollover_description_inner')
news_p_all
news_p = soup.find('div', class_='rollover_description_inner').text
news_p

# .strip()
results = soup.find_all('a')
results
title = soup.find('div', class_='content_title')
title
 browser.quit()
# JPL Mars Space Images - Featured Image

# Setup splinter
executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=False)
url = 'https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/index.html'
browser.visit(url)
response = requests.get(url)
html = browser.html
soup = BeautifulSoup(html, 'html.parser')
browser.find_by_tag('button')[1].click()
# browser.is_element_present_by_text('more info', wait_time=1)
html = browser.html
soup = BeautifulSoup(html, 'html.parser')
image = soup.find('img')
image


image_url = soup.find('img', class_= 'fancybox-image')['src']

image_url

base_url = 'https://data-class-jpl-space.s3.amazonaws.com/JPL_Space/'
mars_image_url = base_url + image_url 
mars_image_url
 browser.quit()<jupyter_output><empty_output><jupyter_text>Mars Facts<jupyter_code># Setup splinter
executable_path = {'executable_path': ChromeDriverManager().install()}
browser = Browser('chrome', **executable_path, headless=False)
url = 'https://space-facts.com/mars/'
browser.visit(url)
html = browser.html
response = requests.get(url)
# soup = BeautifulSoup(response.text, 'html.parser')
soup = BeautifulSoup(html, 'html.parser')
print(soup.prettify())
ul = browser.find_by_id('facts').text
ul
fact_table = soup.find(id ='facts')
# fact_table


for rows in fact_table.find_all('strong'):
#     print('Some facts about Mars include: ')
    print(rows.text)
test_table = soup.find('table', class_='tablepress')
test_table
print(test_table.prettify())
for rows in test_table.find_all('tr'):
    print(rows.text)
# key = test_table.find_all('td', class_='column-1')
        
for key in test_table.find_all('td', class_='column-1'):
    
#     print(key.text)
    
    key_text = key.text
    
    print(key_text)
{key_text}
for value in test_table.find_all('td', class_='column-2'):
    
    # prints the p tag content
    print(value.text)
data_soup.attrs={"key_text": "value"}
import pandas as pd

df = pd.DataFrame()
df['Col1'] = key_text
df['Col2'] = textvalue
df
import pandas as pd

df = pd.DataFrame()
df['Col1'] = col1List
df['Col2'] = col2List
df['Col3'] = col3List
df['Col4'] = col4List
test_table = soup.find('table', class_='tablepress')

mars_df = test_table[1]
mars_df
!pip install lxml
import pandas as pd
# pip3 install lxml
tables = pd.read_html('https://space-facts.com/mars/')

mars_df = tables[1]

# Rename columns and set index
mars_df.columns=['description', 'value' , 'Earth']
mars_df
# Use Pandas to convert the data to a HTML table string
facts_table = [mars_df.to_html(classes='data table table-borderless', index=False, header=False, border=0)]
facts_table
# attempting to chain query elements

# hippo = browser.find_by_css('.ul.li.strong')
# hippo = soup.find_by_tag('.ul.li')

# hippo
results = soup.find('tr', class_='row-1')
results
results = soup.find_all('tr')
results
title_text= test_table.text
title_text
# title_text.strip()
# Then search in that div_container for all p tags with class "hello"
# for ptag in test_table.find_all('tr', class_='row-1'):
for ptag1 in test_table.find_all('td', class_='column-1'):
    
    # prints the p tag content
    print(ptag1.text)
for row in test_table.find_all('tr', class_ = 'row-1'):
    print(row.text)
uls = browser.find_by_tag('ul').text
# lis = uls.find_by_tag('li').text
# lis
uls
def getFax(URL):
    res = requests.get(URL)

    try:
        soup = BeautifulSoup(res.content, "lxml")
        table = soup.find("table", {"class":"wikitable sortable"})
    except AttributeError:
        print("Error creating/navigating soup object")

    tr = table.find_all("tr")

    for _tr in tr:
        td = _tr.find_all("td")
        for _td in td:
            a = _td.find_all("a")
            for _a in a:
                print(_a.text.encode("utf-8"))

getFax("https://space-facts.com/mars/")
results = soup.find_all('strong')
results
for ftag1 in test_table.find_all('td', class_='column-2'):
    
    # prints the p tag content
    print(ftag1.text)
for ptag2 in test_table.find_all('td', class_='column-1'):
        
        print(ptag2.text)
        
for ftag2 in test_table.find_all('td', class_='column-2'):    

        print(ftag2.text)
        
        
ptag2
ptag_text = ptag2.text
ptag_text
# i=0
# counter=0

for i in test_table:
    try: 
        ptag = test_table.find_all('td', class_='column-1')
        
        ftag = test_table.find_all('td', class_='column-2')
        
        if (ptag and ftag):
            
            try:
                ptag_first = 
                
                ftag_first = 
#             ptag = ptag.strip()
#             ftag = ftag.strip()
            
#             print(ptag[0], ftag[0])
            print(ptag, ftag)
#             i += 1

    
    except AttributeError as e:
        print(e)   
        
        
# title_text= test_table.text
# title_text
# title_text.strip()        
# def marsfacts(URL):

try:
    table = soup.find("table", {"class":"tablepress"})
except AttributeError:
    print("Error creating/navigating soup object")

tr = table.find_all("tr")

for _tr in tr:
    td = _tr.find_all("td")
    for _td in td:
        a = _td.find_all("td", class_='column-1')
        b = td.find_all("td", class_='column-2')
        for _a in a:
            print(_a.text.encode("utf-8"))
        for _b in b:
            print(_b.text.encode("utf-8"))
# marsfacts("https://space-facts.com/mars/")
output_dict = dict()
counter = 1
for e in results:
  if e["class"] == "column-1":
    output_dict[e]
  if e["class"] == "column-2" :
    output.append(e)
  counter += 1

ivr = soup.find('div')
ivr
# ivs = browser.find_by_tag('td', class_='column-1')[0]
ivs = soup.find('td', class_='column-1')

ivs
# <tr class="row-1 odd"><td class="column-1"><strong>Equatorial Diameter:</strong></td><td class="column-2">6,792 km<br/></td></tr>

soup.find('td', class_='column-1').text

len_list = len(soup.find('td'))
keyword = 'column-'

for i in len_list -1:
    counter = 1
    soup.find('td', class_=keyword+counter.string())
    counter += 1
    







soup.find('td', class_='column-2').text

 browser.quit()
# Visit the USGS Astrogeology site here to obtain high resolution images for each of Mar's hemispheres.

# Setup splinter
executable_path = {'executable_path': ChromeDriverManager().install()}
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

response = requests.get(url)
# soup = BeautifulSoup(response.text, 'html.parser')
soup = BeautifulSoup(html, 'html.parser')
print(soup.prettify())

# fact_table = soup.find(id ='facts')
collapsible_results = soup.find_all('div', class_="collapsible results")
collapsible_results
names_list = []

_results = soup.find_all('div', class_="collapsible results")
hemispheres = _results[0].find_all('h3')

for name in hemispheres:
    names_list.append(name.text)

names_list
# click each of the links to the hemispheres in order to find the image url to the full resolution image.

url_list = []

a_tags = _results[0].find_all('a')


for item in a_tags:
    
    if (item.img):
        
        url = 'https://astrogeology.usgs.gov/' + item['href']
        
        url_list.append(url)

url_list
# Save both the image url string for the full resolution hemisphere image, and the Hemisphere title containing the hemisphere name. Use a Python dictionary to store the data using the keys img_url and title

full_img_list = []


for url in url_list:
    
    browser.visit(url)
    
    html = browser.html
    soup = BeautifulSoup(html, 'html.parser')
    
    results = soup.find_all('img', class_='wide-image')
    relative_img_path = results[0]['src']
    
    img_link = 'https://astrogeology.usgs.gov/' + relative_img_path
    
    full_img_list.append(img_link)

full_img_list
# Append the dictionary with the image url string and the hemisphere title to a list. This list will contain one dictionary for each hemisphere.


name_links = zip(names_list, full_img_list)

image_urls_list = []

for title, img in name_links:
    
    title_url_dict = {}
    
    title_url_dict['title'] = title
    title_url_dict['img_url'] = img
    
    image_urls_list.append(title_url_dict)

image_urls_list
 browser.quit()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14354942924833083, 'fraction_numerical': 0.010015076459185871, 'mean_word_length': 3.799483204134367, 'pattern_counts': {'":': 4, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '484455', 'license': 'ADSL', 'n_tokens_mistral': 3347, 'n_tokens_neox': 3266, 'n_words': 703, 'path': 'mission_to_mars.ipynb', 'repo_name': 'edowager/web-scraping-challenge', 'size': '9286'}