【发布时间】:2021-11-19 16:15:40
【问题描述】:
我想导入一个包含 url 列表的 txt,并从每个 url 中提取并将其保存在 cvs 文件中,但我卡住了
首先我导入 txt 没问题,但是当我想遍历每一行时,我只是从第一行中提取
library(rvest)
library(tidyr)
library(dplyr)
for(i in seq(list_url)) {
text <- read_html(list_url$url[i]) %>%html_nodes("tr~ tr+ tr strong") %>%html_text()}
我只是从第一个 url 中获取值形式的结果,我想要从 url 中提取的所有数据帧
edit : list_ url 文件已满是这个 url..
http://consultas.pjn.gov.ar/cuantificacion/civil/vida_po_detalle_caso.php?numcas=_b8I7G9olKAukGNlsRE6RHSYaYPu8YLjhTEW15HEuj4。 http://consultas.pjn.gov.ar/cuantificacion/civil/vida_po_detalle_caso.php?numcas=ewwF4WmHAnOkCg8Y_XIFH705H_O5hJL9uB5hztOhrsE。 http://consultas.pjn.gov.ar/cuantificacion/civil/vida_po_detalle_caso.php?numcas=Z9BDo7ACNDbsUwTiVFTe9aKFfcLAxxnU2AtL6DCloX4。 http://consultas.pjn.gov.ar/cuantificacion/civil/vida_po_detalle_caso.php?numcas=NZPRa9SoKHVJQcZ64_4zVgcLSNKmHZ4MtorPu23MUPg.
【问题讨论】:
-
能否提供
list_url中的数据。请参阅stackoverflow.com/questions/5963269/… 寻求帮助 -
您在每次传递中都覆盖了您的
text对象,不确定人们会有什么不同的期望。试试out <- do.call(rbind, lapply(list_url, function(url) html_text(html_nodes(read_html(url), "...")))) -
我只是用 list_url 的数据举例
-
请按原样提供列表,而不是指向网址的链接。你应该使用
dput(list_url)。将 dput 的输出粘贴到您的问题中。