本文介绍了R readHTMLTable加载外部实体失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在笔记本电脑上运行这行程序时,
When I run the line on my laptop,
table500 <- readHTMLTable('http://en.wikipedia.org/wiki/List_of_S%26P_500_companies')[[1]]
当我在桌面上运行它时,收到错误
it gets the data. When I run it on my desktop, I receive the error
Error: failed to load external entity "http://en.wikipedia.org/wiki/List_of_S%26P_500_companies".
所以我猜这个问题与我的桌面上的网络设置有关,最简单的想法是什么可以是。任何建议?
So I'm guessing the problem has something to do with network settings in my desktop, I haven't the slightest idea what it could be though. Any suggestions?
推荐答案
在我在评论中提到的链接中,您可以使用 RCurl
和 httr
包。这里,我提供使用 rvest
包的解决方案。
In the link that I mentioned in the comment, you can find solutions using RCurl
and httr
package. Here, I provide the solution using rvest
package.
library(rvest)
kk<-html("http://en.wikipedia.org/wiki/List_of_S%26P_500_companies")%>%
html_table(fill=TRUE)%>%
.[[1]] //table 1 only
head(kk)
Ticker symbol Security SEC filings GICS Sector GICS Sub Industry Address of Headquarters
1 MMM 3M Company reports Industrials Industrial Conglomerates St. Paul, Minnesota
2 ABT Abbott Laboratories reports Health Care Health Care Equipment & Services North Chicago, Illinois
3 ABBV AbbVie reports Health Care Pharmaceuticals North Chicago, Illinois
4 ACN Accenture plc reports Information Technology IT Consulting & Other Services Dublin, Ireland
5 ACE ACE Limited reports Financials Property & Casualty Insurance Zurich, Switzerland
6 ACT Actavis plc reports Health Care Pharmaceuticals Dublin, Ireland
Date first added CIK
1 66740
2 1800
3 2012-12-31 1551152
4 2011-07-06 1467373
5 2010-07-15 896159
6 884629
这篇关于R readHTMLTable加载外部实体失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!