抓取网站的特定部分?

时间:2019-04-18 07:11:51

标签: r web-scraping

我有一个用于文档的URL列表(mesa $ fullerurl),我正在尝试在每个网站上抓取一段特定的文本(有关风险因素的段落)。问题是在本节中没有唯一的HTML标签。我能想到的最好的方法是告诉R从“风险因子”标题中提取文本直到下一个标题,然后将其放在新的数据帧k10中,但是我不确定如何在R中指定此内容。 ! 这是我要从中抓取的文档的示例: https://www.sec.gov/Archives/edgar/data/72903/000007290319000010/xcel1231201810-k.htm

sec<-read_html("https://www.sec.gov/cgi-bin/browse-edgar? 
action=getcompany&CIK=0000072903&type=10- 
k&dateb=&owner=exclude&count=40")
xcel<- sec %>%
  html_nodes("#documentsbutton") %>%
  html_attr("href")
xcel<-data.frame(xcel)
xcel$xcell<-paste0("https://www.sec.gov",xcel$xcell)
xcel$fullurl<-paste0(xcel$xcell,xcel$xcel)
as.character(xcel$fullurl)

mesa<-map_dfr(xcel$fullurl, ~ .x %>% read_html() %>%  html_table() %>% . 
[[1]])
mesa<-subset(mesa,mesa$Type=="10-K"|mesa$Type=="10-K/A"|mesa$Type=="10- 
K405")
mesa
s<-gsub("(.*)/.*","\\1",xcel$fullurl)
table(xcel$fullurl)
xcel$fullurl<-s
xcel$fullurl<-paste0(xcel$fullurl,"/") 
mesa$fullerurl<-paste0(xcel$fullurl,mesa$Document)
as.character(mesa$fullerurl)
mesa$Document[mesa$Document == ""] <- NA
mesa$fullerurl 
#Below is the problematic part 
k10<-map_dfr(mesa$fullerurl, ~ .x %>% read_html("") %>%  html_nodes("") 
%>% html_text(""))

0 个答案:

没有答案
相关问题