【发布时间】:2015-09-22 08:58:14
【问题描述】:
我是从网站抓取数据的初学者。我似乎很难使用 XML 或其他包来解释 html 的结构。 谁能帮我从这个网站下载数据?
http://wszw.hzs.mofcom.gov.cn/fecp/fem/corp/fem_cert_stat_view_list.jsp
这是关于来自中国的投资。字符集是中文的。
到目前为止我已经尝试过:
library("rvest")
url <- "http://wszw.hzs.mofcom.gov.cn/fecp/fem/corp/fem_cert_stat_view_list.jsp"
firm <- url %>%
html() %>%
html_nodes(xpath='//*[@id="Grid1MainLayer"]/table[1]') %>%
html_table()
firm <- firm[[1]] head(firm)
【问题讨论】:
-
你试过什么代码。 SO上有数百个这样的例子,网络上有数千个。到目前为止,您为此付出了哪些努力?
-
对不起,我没有尝试很多代码。
library("rvest") url <- "http://wszw.hzs.mofcom.gov.cn/fecp/fem/corp/fem_cert_stat_view_list.jsp" firm <- url %>% html() %>% html_nodes(xpath='//*[@id="Grid1MainLayer"]/table[1]') %>% html_table() firm <- firm[[1]] head(firm) -
再试一次:
url<-html("http://wszw.hzs.mofcom.gov.cn/fecp/fem/corp/fem_cert_stat_view_list.jsp")selector_name<-"tr.listTableBody td div"fnames<-html_nodes(url, selector_name) %>% html_text()head(fnames)变量搞砸了。我怎样才能把它们变成一张桌子? @hrbrmstr @Lorenzo Rossi
标签: r web-scraping rvest