Google Earth - Brown University
[Pages:39]Google Earth
April 14 2016
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
1
Web Scraping Introduction
? Why isn't there a nice "importXML" in Python?
? xml.etree.ElementTree module
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
2
Using xml.etree.ElementTree
import xml.etree.ElementTree as et
filename = 'example.xml'
file = open(filename, 'r') contents = file.read() file.close()
tree = et.fromstring(contents) tree.tag
for node in tree.findall('car'): for subnode in node.findall('year'): print(subnode.tag, ": ", subnode.text) for subnode in node.findall('color'): print(subnode.tag, ": ", subnode.text) print('---')
contents:
2010 black 2012 red 2014 yellow
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
3
Using xml.etree.ElementTree
import xml.etree.ElementTree as et
filename = 'example.xml'
file = open(filename, 'r') contents = file.read() file.close()
Internal rep. of the XML
tree = et.fromstring(contents) tree.tag
for node in tree.findall('car'): for subnode in node.findall('year'): print(subnode.tag, ": ", subnode.text) for subnode in node.findall('color'): print(subnode.tag, ": ", subnode.text) print('---')
contents:
2010 black 2012 red 2014 yellow
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
4
Using xml.etree.ElementTree
import xml.etree.ElementTree as et
filename = 'example.xml'
file = open(filename, 'r') contents = file.read() file.close()
Gives back list of "car" nodes
tree = et.fromstring(contents) tree.tag
for node in tree.findall('car'): for subnode in node.findall('year'): print(subnode.tag, ": ", subnode.text) for subnode in node.findall('color'): print(subnode.tag, ": ", subnode.text) print('---')
contents:
2010 black 2012 red 2014 yellow
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
5
Using xml.etree.ElementTree
import xml.etree.ElementTree as et
filename = 'example.xml'
file = open(filename, 'r') contents = file.read() file.close()
Searches for "year" inside " car
tree = et.fromstring(contents) tree.tag
for node in tree.findall('car'): for subnode in node.findall('year'): print(subnode.tag, ": ", subnode.text) for subnode in node.findall('color'): print(subnode.tag, ": ", subnode.text) print('---')
contents:
2010 black 2012 red 2014 yellow
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
6
Using xml.etree.ElementTree
import xml.etree.ElementTree as et
filename = 'example.xml'
file = open(filename, 'r') contents = file.read() file.close()
Gives back list of " year" nodes
tree = et.fromstring(contents) tree.tag
for node in tree.findall('car'): for subnode in node.findall('year'): print(subnode.tag, ": ", subnode.text) for subnode in node.findall('color'): print(subnode.tag, ": ", subnode.text) print('---')
contents:
2010 black 2012 red 2014 yellow
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
7
Using xml.etree.ElementTree
import xml.etree.ElementTree as et
filename = 'example.xml'
file = open(filename, 'r') contents = file.read() file.close()
tree = et.fromstring(contents) tree.tag
for node in tree.findall('car'): for subnode in node.findall('year'): print(subnode.tag, ": ", subnode.text) for subnode in node.findall('color'): print(subnode.tag, ": ", subnode.text) print('---')
CSCI 0931 - Intro. to Comp. for the Humanities and Social Sciences
contents:
2010 black 2012 red 2014 yellow
subnode.text gives back text subnode.tag gives back tag
8
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- google earth brown university
- python xml pr ocessing with relearn
- ann arbor mi usa
- pharmasug paper ad 211 validating hyperlinks in sdtm
- reading xml introducing xpath
- introducción xml expresiones regulares el paquete
- curso python en 8 clases clase 7 xml
- better faster smarter
- python xml unittest documentation read the docs
- python xml parsing complete examples tutorial kart
Related searches
- google earth ancient rome
- young earth old earth debate
- old earth vs young earth debate
- google earth asteroid impact simulator
- brown university philosophy faculty
- brown university biology
- brown university marine biology
- brown university biology concentration
- brown university marine biology program
- brown university biology ranking
- google earth weather satellite
- brown university high school summer program