【发布时间】:2021-01-28 05:21:41
【问题描述】:
我有一个 url 列表,每个 url 都包含一个指向 pdf 文档的 url。我想使用 R 提取和下载 pdf 文档。这是我到目前为止的代码:
从reliefweb.int 下载数据
#get all the results for the Afghanistan HNO search
result <- GET("https://api.reliefweb.int/v1/reports?appname=rwint-user-0&profile=list&preset=latest&slim=1&query[value]=(primary_country.iso3%3A%22afg%22)%20AND%20ocha_product%3A%22Humanitarian%20Needs%20Overview%22%20AND%20source%3A%22UN%20Office%20for%20the%20Coordination%20of%20Humanitarian%20Affairs%22&query[operator]=AND")
#create a list of all the urls listed in the search page
rawToChar(result$content)
result2<- fromJSON(rawToChar(result$content))
urllist<- result2[["data"]][["fields"]][["url"]]
#Extraxt links to the pdf docs
urlpdf<- lapply(urllist,read_html)
使用此代码,我有一个 html 节点列表,但我被困在如何从中提取 .pdf 网址上。知道如何进行,或者是否有更有效的方法?
【问题讨论】:
标签: r html-parsing