作者david31408 (Hope)
看板R_Language
标题[问题] 抓取网页
时间Fri Aug 12 18:05:15 2016
[软体熟悉度]:
请把以下不需要的部份删除
入门(写过其他程式,只是对语法不熟悉)
[问题叙述]:
请简略描述你所要做的事情,或是这个程式的目的
大家好,我是R的新手,所以最近在练习
想要用XML这个package试着抓取 baseballreference的资料试看看
由於很菜,所以就先乱试,程式码跟提示如下
会不会不是所有的网页都可以用xml抓取?
> library("XML", lib.loc="~/R/win-library/3.2")
> url <- "http://www.baseball-reference.com/leaders/H_career.shtml"
> Hits <- readHTMLTable(url)
Error in UseMethod("xpathApply") :
no applicable method for 'xpathApply' applied to an object of class "NULL"
在上面的case中,不知道为什麽会出现这样的error message
但我猜网页本身不是table
後来又试了方法2
> url <- "http://www.baseball-reference.com/leaders/H_career.shtml"
> x <- xmlParse(url)
Error message 如下
Specification mandate value for attribute itemscope
attributes construct error
Couldn't find end of Start Tag html line
Extra content at the end of the document
Error: 1: Specification mandate value for attribute itemscope
2: attributes construct error
3: Couldn't find end of Start Tag html line 1
4: Extra content at the end of the document
可能baseballreference防止这样?
谢谢大家教学 :)
[关键字]:
MLB, XML
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.109.55.227
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1470996319.A.26D.html
1F:→ andrew43: 你在板上先爬个文吧。 08/12 20:26
2F:→ andrew43: 另外,你这样「乱试」不是学习的好方法。多看说明文件 08/12 20:27
3F:→ andrew43: 和前人的例子。 08/12 20:27
4F:→ david31408: 谢谢 这算是爬虫吗? 08/12 20:33
5F:→ celestialgod: 是爬虫 08/12 22:20
6F:→ david31408: 了解!! 谢谢:) 08/12 23:43