我正在寻找使用 R 的化学数据库中的一些数据,主要是name
,CAS Number
和molecular weight
现在。但是,我无法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)
但是,当我尝试创建时name_html
,R 只返回字符(空)。我正在使用SelectorGadget
获取 HTML 节点,但我注意到这SelectorGadget
给了我一个与 Inspector 在 Google Chrome 中所做的不同的节点。我在这行代码中都试过了".short .breakword"
,".summary-title short .breakword"
但都没有给我我想要的东西。