使用rvest从COSMIC中获取突变表格
优采云 发布时间: 2022-06-05 10:26使用rvest从COSMIC中获取突变表格
2022的实习生和学徒培养开始啦,所以大家又可以看到了几百个全新的生物信息学知识点整理分享的简书,公众号,语雀账号了。挑选其中一些持久的,优秀的小伙伴的笔记转载到我们《生信技能树》公众号平台:
下面是因INFORnotes的分享了解网页
在学习如何爬取网页之前,要了解网页本身的结构。
用于构建网页的主要语言为 HTML,CSS和Javascript。HTML为网页提供了其实际结构和内容。CSS为网页提供了其样式和外观,包括字体和颜色等细节。Javascript提供了网页功能。在此,我们将主要关注如何使用R包来读取构成网页的 HTML 。
HTML
HTML为一种标记语言,它描述了网页的内容和结构。不同的标签执行不同的功能。许多标签一起形成并包含网页的内容。常见的HTML文档如下所示:
<br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" /><p><br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" />Here's a paragraph of text!<br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" />
<br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" />Here's a second paragraph of text!<br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" /><br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;visibility: visible;overflow-wrap: inherit !important;word-break: inherit !important;" /></p>
每个标签都是"配对"的, 且允许标签彼此嵌套。这种嵌套为 HTML 提供了一个"树状"结构。这种树状结构将告知我们在使用R进行网络抓取时如何查找某些标签。
使用rvest从COSMIC中获取突变表格
安装并导入R包
install.packages(“rvest”)<br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />library(rvest)<br style="outline: 0px;max-width: 100%;box-sizing: border-box;font-size: inherit;color: inherit;line-height: inherit;overflow-wrap: inherit !important;word-break: inherit !important;" />
为了开始解析一个网页,我们首先需要从包含它的计算机服务器请求数据。在revest中,使用read_html(),接受一个web URL作为参数。
以TP53基因为例,在COSMIC网站中检索。在网页右上角点击使用开发人员工具找到URL。
read_html() 函数返回一个列表对象,该对象包含前面讨论的树状结构。 <p>url