Monday, 3 December 2007
Sample python code Exercise 04 prettified
""" Markup Example 04
Adding the accept header for xHTML
author: Julian Harty
edited: 03 December 2007
"""
import urllib
import BeautifulSoup
request = urllib.FancyURLopener()
request.addheader('Accept', 'application/xhtml+xml')
response = request.open("http://www.google.co.uk/m")
content = response.read()
# Display the formatted contents
soup = BeautifulSoup.BeautifulSoup(content)
print soup.prettify()
# write the content to a file so it can be displayed in a browser
f = open("markup_ex04_prettified.xml", "wb")
f.write(content)
f.close()
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment