【发布时间】:2014-04-01 18:48:07
【问题描述】:
我有以下代码我不知道为什么会收到此错误:
rm(list=ls())
require("XML")
# <a href="/music/The+Beatles/Sgt.+Pepper%27s+Lonely+Hearts+Club+Band"
beatles = "http://www.last.fm/music/The+Beatles/"
beatles.albums.page = paste(sep="", beatles, "+albums")
lines = readLines(beatles.albums.page)
album.lines = grep(pattern="href.*link-reference", lines, value=TRUE)
album.names = sub(pattern=".*<h3>(.*)</h3>.*", replacement="\\1", x=album.lines)
album.names = gsub(pattern=" ", replacement="+", x=album.names)
album.names = gsub(pattern="'", replacement="%27", x=album.names)
for (album in album.names[1]) {
print(album)
album.link = paste(sep="", beatles, album)
print(album.link)
tables = readHTMLTable(album.link)
}
有什么想法吗?
【问题讨论】:
-
readHTMLTable(album.link)行导致错误。 -
它有什么问题?怎么解决?
-
last.fm 确实有一个 API - last.fm/api - 这将使这个比刮擦干净得多。
-
他们的 API 有 R 脚本吗?
标签: html regex r web-scraping last.fm