[我正在使用rvest
R
包从this网页中抓取PDF文件,但是当我按名称exposed url
单击AC1-96-21-01-2011.pdf
后,最终链接被公开(作为比特流url-不管是什么)。 ]。最终的pdf文件被隐藏在here中,无法访问。这将阻止rvest
功能read_html()
的所有尝试,因为只有单击上一个链接(在href
上),最终的pdf文件才会打开。复制粘贴不允许我进入pdf文件的xml node
。
<a href="/judgments/handle/123456789/701">Arbitration Case - AC</a>
最终文件位于此URL上,该文件未在href
节点中公开。http://judgmenthck.kar.nic.in/judgments/bitstream/123456789/563560/2/AC1-96-21-01-2011.pdf
因此,如上所述,如何使用rvest
属性中未找到的href
访问pdf文件链接。
我尝试搜索bitstream
,但将我带到其他地方。
我认为您正在寻找错误的节点:
library(rvest)
"http://judgmenthck.kar.nic.in/judgments/handle/123456789/563560" %>%
read_html() %>%
html_nodes(xpath = "//td/a[@target='_blank']") %>%
html_attr("href") %>%
unique() %>%
{grep("[.]pdf", ., value = T)} %>%
paste0("http://judgmenthck.kar.nic.in", .) ->
pdf_url
print(pdf_url)
# [1] "http://judgmenthck.kar.nic.in/judgments/bitstream/123456789/563560/2/AC1-96-21-01-2011.pdf"