1

I have been trying to scrape from a soccer site a table of players as well as links to individual player's profile. I use Chrome's Inspect element to get the xpath (is that a good idea?), and yet I got no result still.

The web page is Liverpool's page. Below is my attempt to scrape both the player table and the links to each player profile.

require(XML)

team_name <- "Liverpool"
url <- paste("http://www.football-lineups.com/team/", team_name, 
             "/Champions_League_2004_2005/Stats/Most_Capped/", sep='')
url.data <- htmlParse(url)
table <- xpathApply(url.data,
  '//*[@id="mainarea"]/tbody/tr/td[1]/table[2]', xmlValue)
links <- xpathApply(url.data,
  '//*[@id="mainarea"]/tbody/tr/td[1]/table[2]/tbody/tr[2]/td[2]/a/@href', xmlValue)
table #NULL
links #NULL

EDIT: Scrapping all the links on the web page work, however. I must do something wrong above!

links2 <- xpathSApply(url.data, "//a/@href")
links2 # a bunch of links
4

0 回答 0