Rvest web刮取返回空字符
我正在寻找使用R从化学数据库中获取一些数据,目前主要是Rvest web刮取返回空字符,r,web-scraping,rvest,pubchem,R,Web Scraping,Rvest,Pubchem,我正在寻找使用R从化学数据库中获取一些数据,目前主要是名称,CAS编号,以及分子量。但是,我在获取rvest以提取我要查找的信息时遇到困难。这是我目前掌握的代码: library(rvest) library(magrittr) # Read HTML code from website # I am using this format because I ultimately hope to pull specific items from several different website
名称
,CAS编号
,以及分子量
。但是,我在获取rvest
以提取我要查找的信息时遇到困难。这是我目前掌握的代码:
library(rvest)
library(magrittr)
# Read HTML code from website
# I am using this format because I ultimately hope to pull specific items from several different websites
webpage <- read_html(paste0("https://pubchem.ncbi.nlm.nih.gov/compound/", 1))
# Use CSS selectors to scrape the chemical name
chem_name_html <- webpage %>%
html_nodes(".short .breakword") %>%
html_text()
# Convert the data to text
chem_name_data <- html_text(chem_name_html)
库(rvest)
图书馆(magrittr)
#从网站读取HTML代码
#我之所以使用这种格式,是因为我最终希望从几个不同的网站上获取特定的项目
网页%
html_text()
#将数据转换为文本
化学名称数据我最近在使用rvest
刮取PubChem时遇到了同样的问题。问题在于,当您向下滚动页面时,页面上的信息是使用javascript呈现的,因此rvest
只能从页面获取最少的信息
不过,还有一些变通办法。将所需信息输入R的最简单方法是使用名为的R包
如果您正在查找名称、CAS编号和分子量,则可以执行以下操作:
库(webchem)
您正在尝试获取存款人提供的同义词,对吗?上面的示例仅尝试检索主页上的物质名称,但如果可能,我也希望检索存款人提供的同义词。