# This program uses requests to fetch an HTML page and BeautifulSoup to parse it

import requests, bs4

# Creating a BeautifulSoup Object from HTML
res = requests.get("http://nostarch.com")
res.raise_for_status()  # Raise error if nothing fetched
noStarchSoup = bs4.BeautifulSoup(res.text, "lxml")  # Specify parser to avoid warning
print(type(noStarchSoup))

exampleFile = open("example.html")
exampleSoup = bs4.BeautifulSoup(exampleFile, "lxml")
print(type(exampleSoup))

# Finding an Element with the select() Method
exampleFile = open("example.html")
exampleSoup = bs4.BeautifulSoup(exampleFile.read(), "lxml")
elems = exampleSoup.select("#author")
print(type(elems))
print(len(elems))
print(type(elems[0]))
print(elems[0].getText())
print(str(elems[0]))
print(elems[0].attrs)

# This program uses requests to fetch an HTML page and BeautifulSoup to parse it

import requests, bs4

# Creating a BeautifulSoup Object from HTML
res = requests.get("http://nostarch.com")
res.raise_for_status()  # Raise error if nothing fetched
noStarchSoup = bs4.BeautifulSoup(res.text, "lxml")  # Specify parser to avoid warning
print(type(noStarchSoup))

exampleFile = open("example.html")
exampleSoup = bs4.BeautifulSoup(exampleFile, "lxml")
print(type(exampleSoup))

# Finding an Element with the select() Method
exampleFile = open("example.html")
exampleSoup = bs4.BeautifulSoup(exampleFile.read(), "lxml")
elems = exampleSoup.select("#author")
print(type(elems))
print(len(elems))
print(type(elems[0]))
print(elems[0].getText())
print(str(elems[0]))
print(elems[0].attrs)

pElems = exampleSoup.select('p')
print(str(pElems[0]))
print(pElems[0].getText())
print(str(pElems[1]))
print(pElems[1].getText())
print(str(pElems[2]))
print(pElems[2].getText())

Update P02_parseHTML added p elements example