html_nodes函数R语言,【已解决】R语言中如何查询库函数的语法和功能说明

htmlParse(file, ignoreBlanks = TRUE, handlers = NULL, replaceEntities = FALSE,

asText = FALSE, trim = TRUE, validate = FALSE, getDTD = TRUE,

isURL = FALSE, asTree = FALSE, addAttributeNamespaces = FALSE,

useInternalNodes = TRUE, isSchema = FALSE, fullNamespaceInfo = FALSE,

encoding = character(),

useDotNames = length(grep("^\\.", names(handlers))) > 0,

xinclude = TRUE, addFinalizer = TRUE,

error = htmlErrorHandler, isHTML = TRUE,

options = integer(), parentFirst = FALSE)

xmlSchemaParse(file, asText = FALSE, xinclude = TRUE, error = xmlErrorCumulator())

Arguments

file

The name of the file containing the XML contents. This can contain \~ which is expanded to the user’s home directory. It can also be a URL. See isURL. Additionally, the file can be compressed (gzip) and is read directly without the user having to de-compress (gunzip) it.

ignoreBlanks

logical value indicating whether text elements made up entirely of white space should be included in the resulting ‘tree’.

handlers

Optional collection of functions used to map the different XML nodes to R objects. Typically, this is a named list of functions, and a closure can be used to provide local data. This provides a way of filtering the tree as it is being created in R, adding or removing nodes, and generally processing them as they are constructed in the C code.

In a recent addition to the package (version 0.99-8), if this is specified as a single function object, we call that function for each node (of any type) in the underlying DOM tree. It is invoked with the new node and its parent node. This applies to regular nodes and also comments, processing instructions, CDATA nodes, etc. So this function must be sufficiently general to handle them all.

replaceEntities

logical value indicating whether to substitute entity references with their text directly. This should be left as False. The text still appears as the value of the node, but there is more information about its source, allowing the parse to be reversed with full reference information.

asText

logical value indicating that the first argument, ‘file’, should be treated as the XML text to parse, not the name of a file. This allows the contents of documents to be retrieved from different sources (e.g. HTTP servers, XML-RPC, etc.) and still use this parser.

trim

whether to strip white space from the beginning and end of text strings.

validate

logical indicating whether to use a validating parser or not, or in other words check the contents against the DTD specification. If this is true, warning messages will be displayed about errors in the DTD and/or document, but the parsing will proceed except for the presence of terminal errors. This is ignored when parsing an HTML document.

getDTD

logical flag indicating whether the DTD (both internal and external) should be returned along with the document nodes. This changes the return type. This is ignored when parsing an HTML document.

isURL

indicates whether the file argument refers to a URL (accessible via ftp or http) or a regular file on the system. If asText is TRUE, this should not be specified. The function attempts to determine whether the data source is a URL by using

asTree

this only applies when on passes a value for the handlers argument and is used then to determine whether the DOM tree should be returned or the handlers object.

addAttributeNamespaces

a logical value indicating whether to return the namespace in the names of the attributes within a node or to omit them. If this is TRUE, an attribute such as xsi:type="xsd:string" is reported with the name xsi:type. If it is FALSE, the name of the attribute is type.

useInternalNodes

a logical value indicating whether to call the converter functions with objects of class XMLInternalNode rather than XMLNode. This should make things faster as we do not convert the contents of the internal nodes to R explicit objects. Also, it allows one to access the parent and ancestor nodes. However, since the objects refer to volatile C-level objects, one cannot store these nodes for use in further computations within R. They “disappear” after the processing the XML document is completed.

If this argument is TRUE and no handlers are provided, the return value is a reference to the internal C-level document pointer. This can be used to do post-processing via XPath expressions using

This is ignored when parsing an HTML document.

isSchema

a logical value indicating whether the document is an XML schema (TRUE) and should be parsed as such using the built-in schema parser in libxml.

fullNamespaceInfo

a logical value indicating whether to provide the namespace URI and prefix on each node or just the prefix. The latter (FALSE) is currently the default as that was the original way the package behaved. However, using TRUE is more informative and we will make this the default in the future.

This is ignored when parsing an HTML document.

encoding

a character string (scalar) giving the encoding for the document. This is optional as the document should contain its own encoding information. However, if it doesn’t, the caller can specify this for the parser. If the XML/HTML document does specify its own encoding that value is used regardless of any value specified by the caller. (That’s just the way it goes!) So this is to be used as a safety net in case the document does not have an encoding and the caller happens to know theactual encoding.

useDotNames

a logical value indicating whether to use the newer format for identifying general element function handlers with the ‘.’ prefix, e.g. .text, .comment, .startElement. If this is FALSE, then the older format text, comment, startElement, … are used. This causes problems when there are indeed nodes named text or comment or startElement as a node-specific handler are confused with the corresponding general handler of the same name. Using TRUE means that your list of handlers should have names that use the ‘.’ prefix for these general element handlers. This is the preferred way to write new code.

xinclude

a logical value indicating whether to process nodes of the form to insert content from other parts of (potentially different) documents. TRUE means resolve the external references; FALSE means leave the node as is. Of course, one can process these nodes oneself after document has been parse using handler functions or working on the DOM. Please note that the syntax for inclusion using XPointer is not the same as XPath and the results can be a little unexpected and confusing. See the libxml2 documentation for more details.

addFinalizer

a logical value indicating whether the default finalizer routine should be registered to free the internal xmlDoc when R no longer has a reference to this external pointer object. This is only relevant when useInternalNodes is TRUE.

error

a function that is invoked when the XML parser reports an error. When an error is encountered, this is called with 7 arguments. See

If parsing completes and no document is generated, this function is called again with only argument which is a character vector of length 0. This gives the function an opportunity to report all the errors and raise an exception rather than doing this when it sees th first one.

This function can do what it likes with the information. It can raise an R error or let parser continue and potentially find further errors.

The default value of this argument supplies a function that cumulates the errors

If this is NULL, the default error handler function in the package

isHTML

a logical value that allows this function to be used for parsing HTML documents. This causes validation and processing of a DTD to be turned off. This is currently experimental so that we can implement htmlParse with this same function.

options

an integer value or vector of values that are combined (OR’ed) together to specify options for the XML parser. This is the same as the options parameter for

parentFirst

a logical value for use when we have handler functions and are traversing the tree. This controls whether we process the node before processing its children, or process the children before their parent node.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: nx.draw_networkx_nodes函数用于绘制网络的节点。它的基本用法如下: ```python import networkx as nx import matplotlib.pyplot as plt # 创建一个空的无向图 G = nx.Graph() # 向图添加节点 G.add_node(1) G.add_node(2) G.add_node(3) # 绘制节点 pos = nx.spring_layout(G) # 计算节点的布局位置 nx.draw_networkx_nodes(G, pos, node_size=300, node_color='r', alpha=0.8) plt.show() ``` 上述代码,首先创建了一个空的无向图G,并向其添加了三个节点。然后使用nx.spring_layout计算节点的布局位置,最后使用nx.draw_networkx_nodes函数绘制节点。其,pos表示节点的位置,node_size表示节点的大小,node_color表示节点的颜色,alpha表示节点的透明度。 更多的绘制节点的参数可以查看官方文档:https://networkx.github.io/documentation/latest/reference/generated/networkx.drawing.nx_pylab.draw_networkx_nodes.html。 ### 回答2: nx.draw_networkx_nodes函数是NetworkX库用于绘制节点的函数。该函数用于绘制代表图的节点的可视化表示。 具体用法如下: nx.draw_networkx_nodes(G, pos=None, node_size=300, node_color='r', node_shape='o', alpha=None) 其,参数G表示输入的图,可以通过G.nodes()方法获取到图的所有节点。 pos表示节点的位置,可以是一个映射字典,其键是节点的名称,值是节点的坐标;也可以是一个布局函数,用于自动排列节点的位置。 node_size表示节点的大小,默认为300。 node_color表示节点的颜色,默认为‘r’(红色),可以是字符串形式的颜色名称、RGB元组、RGBA元组或颜色映射。 node_shape表示节点的形状,默认为‘o’(圆形),可以是字符串形式的形状名称或自定义的形状。 alpha表示节点的透明度,默认为None,即完全不透明。可以是0~1之间的值,表示透明度的程度。 使用该函数可以在绘图窗口显示代表图节点的形状,并根据指定的参数调整节点的位置、大小和颜色等属性。 ### 回答3: nx.draw_networkx_nodes函数是NetworkX用于绘制节点的函数。它可以将节点绘制在一个二维空间的指定位置上。 nx.draw_networkx_nodes函数的参数包括: 1. G:一个NetworkX图对象,表示要绘制节点的图。 2. pos:一个字典,用于指定节点的位置。字典的键是节点,值是二维坐标元组。如果没有提供该参数,节点将会在二维平面上自动生成位置。 3. node_color:用于指定节点的颜色。可以是一个颜色字符串(如'red'),也可以是一个颜色列表,每个节点对应一个颜色。如果没有提供该参数,默认颜色是蓝色。 4. node_size:用于指定节点的尺寸。可以是一个整数,表示所有节点的大小相同;也可以是一个整数列表,每个节点对应一个尺寸。如果没有提供该参数,默认尺寸是300。 5. alpha:用于指定节点的透明度。它可以是一个0到1之间的浮点数,表示节点的透明度;或者是一个浮点数列表,每个节点对应一个透明度。如果没有提供该参数,默认值是1(不透明)。 6. cmap:用于指定节点的颜色映射。它可以是一个Matplotlib的Colormap对象,从节点的值到颜色之间进行映射。如果没有提供该参数,默认使用viridis色图。 7. vmin和vmax:用于指定颜色映射的范围。如果提供了cmap参数,那么vmin和vmax将会影响节点的颜色映射范围。如果没有提供该参数,默认值是节点值的最小和最大值。 通过调用nx.draw_networkx_nodes函数,可以将节点绘制在二维空间,以便更好地可视化网络结构。可以根据节点的属性来设置节点的颜色、尺寸和透明度,以及使用颜色映射对节点进行更加精细的可视化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值