我想在这个 website 上抓取数据表.
我检查了此页面的页面源,页面源中不存在该表。
然后我在刷新网站时查看了网络信息,数据表似乎是通过向这个url发送POST请求获得的:
http://datacenter.mep.gov.cn:8099/ths-report/report!list.action
然后我尝试发送 POST 请求,但状态 500 一无所获。
我想知道是否可以通过使用 R 来删除这张表?
谢谢。
最佳答案
好侦探!
它正在制作 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
关于r - 抓取页面源中不存在的数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46604365/