2017-10-06 2 views
4

このwebsiteのデータテーブルを削りたいですか?ページソースに存在しないスクラップデータテーブル

このページのページソースを確認しても、そのページはページソースに存在しません。ウェブサイトを更新すると

は、それから私は、ネットワーク情報を確認し、データテーブルは、このURLにPOSTリクエストを送信することにより得られるようだ:

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

それから私は、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 
関連する問題