在一台计算机上(Windows 7),此代码运行良好:
library(XML)
library(RCurl)
library(xtable)
library(httr)
library(xml2)
theurl <- "https://biz.yahoo.com/c/s.html"
webpage <- content(GET(theurl))
tables <- readHTMLTable(webpage)
splits <- tables[[length(tables)]]
splits
> splits
Payable Ex\nDate Company Symbol Optionable? Ratio Announced Add\nTo MyCalendar
1 <NA> <NA> <NA> <NA> <NA> <NA> <NA>
2 May 19 May 20 Alliant Energy LNT Y 2-1 Apr 20 Add
3 May 27 May 30 Stock Yards Bancorp SYBT N 3-2 May 02* Add
在Windows Server 2012上出现错误:
tables <- readHTMLTable(webpage)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘readHTMLTable’ for signature ‘"xml_document"’
可能是什么原因? 有没有其他可能解析这个www?
答案 0 :(得分:1)
readHTMLTable不支持https。请参阅示例中的?readHTMLTable:
## Not run:
## This changed to using https: in June 2015, and that is unsupported.
# u = "http://en.wikipedia.org/wiki/World_population"
u = "https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population"
要解决同一问题,请参阅this answer。