Btibert3
7/10/2013 - 2:27 AM

XPATH Examples

XPATH Examples

#######
## about
#######
# searches the ENTIRE document for a class
# assumes that the class you want is homogenous across whole document


## //* search the entire document
## can search by classes
## a subsuquent // allows us to further search the match


## requires the parseHTML
tmpweb = htmlParse(getURL(U))

## get all of the data we need for the matching classes
## schoolname
## http://goo.gl/YMMPE
## point is to extract class -- ASSUMES UNIQUE ACROSS WHOLE DOCUMENT
PATTERN = '//*[@class="schoolname"]'
xpathSApply(tmpweb, PATTERN)


## reference a span, get the class, and parse text
URL = "http://nces.ed.gov/collegenavigator/?id=164739"
page = getURL(URL)
doc = htmlParse(page)
XPATH = '//span[@class="ipeds"]/text()'
xpathSApply(doc, XPATH)