【发布时间】:2019-02-02 10:15:17
【问题描述】:
我一直在尝试按照此代码下载嵌入在地图中的 pdf(可以在 here 找到原始文件)。每个 pdf 都涉及巴西的一个自治市(5,570 个文件)。
library(XML)
library(RCurl)
url <- "http://simec.mec.gov.br/sase/sase_mapas.php?uf=RJ&tipoinfo=1"
page <- getURL(url)
parsed <- htmlParse(page)
links <- xpathSApply(parsed, path="//a", xmlGetAttr, "href")
inds <- grep("*.pdf", links)
links <- links[inds]
regex_match <- regexpr("[^/]+$", links, perl=TRUE)
destination <- regmatches(links, regex_match)
for(i in seq_along(links)){
download.file(links[i], destfile=destination[i])
Sys.sleep(runif(1, 1, 5))
}
我已经在其他项目中使用过该代码几次,并且成功了。对于这种特定情况,它没有。事实上,我已经尝试了很多方法来抓取这些文件,但对我来说似乎是不可能的。最近,我得到了以下链接。然后可以结合 uf(状态)和 muncod(市政代码)来下载文件,但我不知道如何将其包含到代码中。
http://simec.mec.gov.br/sase/sase_mapas.php?uf=MT&muncod=5100102&acao=download
提前致谢!
【问题讨论】:
-
你知道可能的状态的值是什么(即,引用每个状态的两个字符代码是什么)?你有一个是 RJ...其他的是什么?
-
没关系,我找到了他们
标签: r google-maps pdf web-scraping