试着在刮水的时候抓住r
我有一个数据表(npi1_列表),其中包含ID号,根据我从网站上抓取的ID号,npi列表将匹配网站中的ID号,并为我提取记录试着在刮水的时候抓住r,r,try-catch,R,Try Catch,我有一个数据表(npi1_列表),其中包含ID号,根据我从网站上抓取的ID号,npi列表将匹配网站中的ID号,并为我提取记录 library("rvest") library("data.table") final<- NULL for(i in 8000:200000){ url<-paste("http://www.npinumberlookup.org/getResultDetails.php?
library("rvest")
library("data.table")
final<- NULL
for(i in 8000:200000){
url<-paste("http://www.npinumberlookup.org/getResultDetails.php?
npinum=",npi1_list[i,1],sep='')
webpage<-read_html(url)
Name<- html_nodes(webpage, 'table:nth-child(8) tr:nth-child(1) td~ td+ td ,
table:nth-child(6) tr:nth-child(1) td~ td+ td')
rank_data <-html_text(Name)
final <- rbind(final,rank_data)
print(i)
Sys.sleep(1)
}
library(“rvest”)
库(“数据表”)
最终库(“rvest”)
库(“数据表”)
最后,你为什么不使用和/或每周更新?敲打一个网站——他们明确规定了最低限度——对于数据(尤其是你在别处可以找到的大量数据)来说并不酷。它们也不是权威来源,所以我还担心数据完整性问题。
library("rvest")
library("data.table")
final<- NULL
for(i in 8000:200000){
repeat{
successful = T
tryCatch({
url<-paste("http://www.npinumberlookup.org/getResultDetails.php?
npinum=",npi1_list[i,1],sep='')
webpage<-read_html(url)
Name<- html_nodes(webpage, 'table:nth-child(8) tr:nth-child(1) td~ td+ td ,
table:nth-child(6) tr:nth-child(1) td~ td+ td')
rank_data <-html_text(Name)
final <- rbind(final,rank_data)
print(i)
}, error = function(e){
print(e)
print(paste0('connection error on ', i))
successful <<- F
})
Sys.sleep(1)
if(successful)
break
}
}