Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中读取HTML中的特定行_Html_R - Fatal编程技术网

在R中读取HTML中的特定行

在R中读取HTML中的特定行,html,r,Html,R,如何在R中读取html中的特定行 由于以下代码,我创建了HTMLInternalDocument对象: url<-myURL html<-htmlTreeParse(url,useInternalNodes=T) 现在我需要从这个html对象中以文本格式获取一行特定的字符,例如,计算每行中的字符数 在R中如何实现这一点?鉴于您正在使用XML库,您将需要使用该库的一个getNodeSet函数,如xpathApply。这需要一些XPath方面的知识,函数使用XPath解析HTMLInt

如何在R中读取html中的特定行

由于以下代码,我创建了HTMLInternalDocument对象:

url<-myURL
html<-htmlTreeParse(url,useInternalNodes=T)
现在我需要从这个html对象中以文本格式获取一行特定的字符,例如,计算每行中的字符数


在R中如何实现这一点?

鉴于您正在使用XML库,您将需要使用该库的一个getNodeSet函数,如xpathApply。这需要一些XPath方面的知识,函数使用XPath解析HTMLInternalDocument。您可以通过使用?xpathApply了解更多信息使用XML库使问题过于复杂。正如Grothendieck指出的,readLines是一个基本函数,它将完成这项工作。大概是这样的:

x <- 10 ## or any other index you want to subset on
html <- readLines(url)
html[x]

这个问题太笼统了,不可能准确地回答。要提取哪些行?如何在HTML源代码中识别它们?您确实应该包括示例数据和所需的输出。有关如何使我们能够帮助您的更多提示,请参阅。一旦您解析了文档,它就是一个解析树,因此没有行。如果您希望将其作为行,请使用readLines在中阅读。