Press the Show algo button to obtain "algo" in the text area.
Click evaluate. If you do not see evaluate, click %hide and shift+enter. Once the text field is generated, paste in it the the XML description copied from in the text area above
%hide
automatic_names(True)
@interact
def read_xml(XML_from_construction='Replace this text with the XML desciption in the text area above'):
global texto
texto=XML_from_construction
Click to the left again to hide and once more to show the dynamic interactive window
'Replace this text with the XML desciption in the text area above'
'Replace this text with the XML desciption in the text area above'
Click evaluate. If you do not see evaluate, click %hide and shift+enter. This cell carries out the main computation. Scroll down (if needed), take a look to the code, and goto to the next cell.
import urllib
# Get a file-like object for the Python Web site's home page.
f = urllib.urlopen("http://gie.cesfelipesegundo.com")
# Read from the object, storing the page's contents in 's'.
s = f.read()
#print s
f.close()
import sgmllib
class MyParser(sgmllib.SGMLParser):
"A simple parser class."
def parse(self, s):
"Parse the given string 's'."
self.feed(s)
self.close()
def __init__(self, verbose=0):
"Initialise an object, passing 'verbose' to the superclass."
sgmllib.SGMLParser.__init__(self, verbose)
self.hyperlinks = []
def start_a(self, attributes):
"Process a hyperlink and its 'attributes'."
for name, value in attributes:
if name == "href":
self.hyperlinks.append(value)
def get_hyperlinks(self):
"Return the list of hyperlinks."
return self.hyperlinks
import urllib, sgmllib
# Get something to work with.
f = urllib.urlopen('http://alpha.sagenb.org/home/pub/93')
s = f.read()
# Try and process the page.
# The class should have been defined first, remember.
myparser = MyParser()
myparser.parse(s)
# Get the hyperlinks.
##print s
print myparser.get_hyperlinks()
Press the Show algo button to obtain "algo" in the text area.
Click evaluate. If you do not see evaluate, click %hide and shift+enter. Once the text field is generated, paste in it the the XML description copied from in the text area above
%hide
automatic_names(True)
@interact
def read_xml(XML_from_construction='Replace this text with the XML desciption in the text area above'):
global texto
texto=XML_from_construction
'Replace this text with the XML desciption in the text area above'
Click evaluate. If you do not see evaluate, click %hide and shift+enter. This cell carries out the main computation. Scroll down (if needed), take a look to the code, and goto to the next cell.
import urllib
# Get a file-like object for the Python Web site's home page.
f = urllib.urlopen("http://gie.cesfelipesegundo.com")
# Read from the object, storing the page's contents in 's'.
s = f.read()
#print s
f.close()
import sgmllib
class MyParser(sgmllib.SGMLParser):
"A simple parser class."
def parse(self, s):
"Parse the given string 's'."
self.feed(s)
self.close()
def __init__(self, verbose=0):
"Initialise an object, passing 'verbose' to the superclass."
sgmllib.SGMLParser.__init__(self, verbose)
self.hyperlinks = []
def start_a(self, attributes):
"Process a hyperlink and its 'attributes'."
for name, value in attributes:
if name == "href":
self.hyperlinks.append(value)
def get_hyperlinks(self):
"Return the list of hyperlinks."
return self.hyperlinks
import urllib, sgmllib
# Get something to work with.
f = urllib.urlopen('http://elpais.com')
s = f.read()
# Try and process the page.
# The class should have been defined first, remember.
myparser = MyParser()
myparser.parse(s)
# Get the hyperlinks.
###print s
###print myparser.get_hyperlinks()
Press the Show algo button to obtain "algo" in the text area.
Click evaluate. If you do not see evaluate, click %hide and shift+enter. Once the text field is generated, paste in it the the XML description copied from in the text area above
%hide
automatic_names(True)
@interact
def read_xml(XML_from_construction='Replace this text with the XML desciption in the text area above'):
global texto
texto=XML_from_construction
'Replace this text with the XML desciption in the text area above'
Click evaluate. If you do not see evaluate, click %hide and shift+enter. This cell carries out the main computation. Scroll down (if needed), take a look to the code, and goto to the next cell.
import urllib
# Get a file-like object for the Python Web site's home page.
f = urllib.urlopen("http://gie.cesfelipesegundo.com")
# Read from the object, storing the page's contents in 's'.
s = f.read()
#print s
f.close()
import sgmllib
class MyParser(sgmllib.SGMLParser):
"A simple parser class."
def parse(self, s):
"Parse the given string 's'."
self.feed(s)
self.close()
def __init__(self, verbose=0):
"Initialise an object, passing 'verbose' to the superclass."
sgmllib.SGMLParser.__init__(self, verbose)
self.hyperlinks = []
def start_a(self, attributes):
"Process a hyperlink and its 'attributes'."
for name, value in attributes:
if name == "href":
self.hyperlinks.append(value)
def get_hyperlinks(self):
"Return the list of hyperlinks."
return self.hyperlinks
import urllib, sgmllib
# Get something to work with.
f = urllib.urlopen('http://elpais.com')
s = f.read()
# Try and process the page.
# The class should have been defined first, remember.
myparser = MyParser()
myparser.parse(s)
# Get the hyperlinks.
###print s
###print myparser.get_hyperlinks()