2017-10-06 2 views
4

website에있는 데이터 테이블을 긁어 내고 싶습니다.페이지 소스에 존재하지 않는 스크래핑 데이터 테이블

이 페이지의 페이지 소스를 확인했지만 페이지 소스에 테이블이 없습니다.

http://datacenter.mep.gov.cn:8099/ths-report/report!list.action 

가 그럼 난 POST 요청을 보내려고하지만, 단지와 아무것도 없어 :

는 다음 나는 웹 사이트를 새로 고칠 때, 데이터 테이블이 URL에 POST 요청을 전송하여 얻은 것 같다 네트워크 정보를 확인 상태 500.

어쨌든 R을 사용하여이 테이블을 긁어 내고 있습니까?

감사합니다.

답변

1

좋은 sleuthing!

나를 위해 GET 요청을하고있었습니다. 이것은 트릭을 할 것으로 보인다. 또한 적절한 타겟을 선택하려고 시도합니다.

library(httr) 
library(rvest) 
library(stringi) 

pg <- read_html("http://datacenter.mep.gov.cn/index!MenuAction.action?name=259206fe260c4cf7882462520e1e3ada") 

html_nodes(pg, "div[onclick]") %>% 
    html_attr("onclick") %>% 
    stri_replace_first_fixed('load("', "") %>% 
    stri_replace_last_regex('",".*$', "") -> report_urls 

head(report_urls) 
## [1] "http://datacenter.mep.gov.cn:8099/ths-report/report!list.action?xmlname=1462849093743" 
## [2] "http://datacenter.mep.gov.cn:8099/ths-report/report!list.action?xmlname=1462764947052" 
## [3] "http://datacenter.mep.gov.cn:8099/ths-report/report!list.action?xmlname=1465594312346" 
## [4] "http://datacenter.mep.gov.cn:8099/ths-report/report!list.action?xmlname=1462844293531" 
## [5] "http://datacenter.mep.gov.cn:8099/ths-report/report!list.action?xmlname=1462844935563" 
## [6] "http://datacenter.mep.gov.cn:8099/ths-report/report!list.action?xmlname=1462845592195" 

rpt_pg <- read_html(report_urls[1]) 
html_table(rpt_pg)[[2]] 
# SO won't let me paste the table 
관련 문제