# Challenge problems:


# ========= Challenges 05/12

Write a few functions to automatically extract information out of html.
You can use the following string to test against:

testhtml="""
<!doctype html>
<head>
    <meta charset="utf-8">
    <title>HTML Parsing: A Primer</title>
    <style> body {background-color: beige; } </style>
</head>
<body>
<h1>Some Content!</h1>
<ul>
<li>You can use python to automatically process webpages.</li>
<li>This is <a id="link" href="http://wikipedia.org">Wikipedia</a></li>
<li><a id="link" href="http://wikipedia.org/wiki/Opossum">All about possums</a></li>
<li><p>Here's a possum:</p>
<img width=200 src="http://homer.stuy.edu/~jvorob/images/possum.jpg">
</li>
</ul>
</body>
</html>
"""

Write a function extractHTMLTags(html):
# This should print out everything between matching pairs of < >
# for test html, this should output the following:
#     !doctype html
#     head
#     meta charset="utf-8"
#     title
#     /title
#     ...

Write a function extractText(html):
# This should print out everything that's NOT in a tag
# for test html, this should output the following:
#     HTML Parsing: A Primer
#     body {background-color: beige; }
#     Some Content!
#     ...

Write a function getAllLinks(html):
# This should print out the URL for every link in a file
# for test html, this should output the following:
#     http://wikipedia.org
#     http://wikipedia.org/wiki/Opossum

Write a function getAllLinks2(html):
# See if you can print not just the URL, but also the link text
# for test html, this should output the following:
#     Wiki (http://wikipedia.org)
#     All about possums (http://wikipedia.org/wiki/Opossum)


# Try your code on some real websites:
# The following function will return the html for a given url
import requests 
def fetchPage(url):
    response = requests.get(url)
    if response.status_code == 200:
        return response.text


#Bonus Challenge:
# See if you can make your code automatically go to other links,
# and search for a specific string on those other pages.
# (this is a basic web-crawler program)




# ========= Challenges 05/03

write a function parseIntegerString(text):
    # This should take a string like "123" and return an integer like 123

write a function parseHexadecimal(text):
    # This should take a string like "1A" and return an integer like 26
    # The numbers 10-15 are represented by "A" through "F"
    # "265B" should parse to 9819

# ========= Challenges 04/06

A "perfect number" is one that is the sum of its factors.
For instance, the factors of 6 are 1, 2, and 3, 
and 1+2+3=6, so 6 is a perfect number.
Write a function firstNPerfect(n) that prints the first n perfect numbers. 


# ========= Challenges 03/28-ish

Write a function isPrime(n)
    # takes a positive integer n
    # returns True if it's prime
    
Write a function printNPrimes(n)
    # Should print the first n primes, starting at 2


Try Solving the following project euler problems:
4: Palindrome Product