2017-11-05 1 views
-1

ID 번호가 포함 된 데이터 테이블 (npi1_list)이 있으며 웹 사이트에서 웹 스크래핑을 수행하는 번호를 기준으로 npi 목록은 웹 사이트의 ID 번호와 일치하며 나를.스크랩 중 r을 시도하고 잡으십시오.

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) 
    } 

이 잘 작동하지만, 시간에 오류가 연결 시간 초과 80 포트 오류가 표시되고 다시 그때의 시도를 구현 할 루프가 종료되었다 곳에서 난을 초기화하고 loop.How의를 다시 실행해야하고 catch 옵션을 사용하여 200000 번까지 자동화 할 수 있습니다.

+0

[다운로드 가능한 전체 데이터베이스] (http://download.cms.gov/nppes/NPI_Files)를 사용하지 않는 이유는 무엇입니까? html) 및/또는 주간 업데이트? 사이트 해머 - ** [20 초 크롤링 지연] (http://www.npinumberlookup.org/robots.txt)의 최소 ** 명시 적 상태 ** - 다른 곳에서 일괄 적으로 찾을 수있는 데이터 esp는 멋지지 않습니다. 그들은 또한 신뢰할 수있는 출처가 아니므로 데이터 무결성 문제에 대해서도 걱정할 것입니다. – hrbrmstr

답변

0
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 
    } 
} 
관련 문제