import webbrowser,requests, bs4
#webbrowser.open('http://inventwithpython.com/')
#res = requests.get('https://automatetheboringstuff.com/files/rj.txt')
#print(type(res))
#print(res.status_code == requests.codes.ok)
#print(len(res.text))
#print(res.text[:250])
# res = requests.get('http://inventwithpython.com/page_that_does_not_exist')
# try:
#    res.raise_for_status()
# except Exception as exc:
#     print('There was a problem: %s' % (exc))

# Always call raise_for_status() after calling requests.get().
# You want to be sure that the download has actually worked before your program continues.

#res = requests.get('https://automatetheboringstuff.com/files/rj.txt')
#res.raise_for_status()
#playFile = open('RomeoAndJuliet.txt', 'wb')
#for chunk in res.iter_content(100000):
#        playFile.write(chunk)
#playFile.close()

# Example
res = requests.get('http://nostarch.com')
res.raise_for_status()
noStarchSoup = bs4.BeautifulSoup(res.text,"html.parser")
print(type(noStarchSoup))
elems = noStarchSoup.select('#author')
print(type(elems))
print(len(elems))
print(type(elems[0]))
print(elems[0].getText())
print(str(elems[0]))
print(elems[0].attrs)
# bs4
# Documentation: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
# Note that RegEx is not possible on <html> websites. It does not parse well...
# See this note: https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags
# Note to self: Remember to update the Readme occasionally!! 
