我正在寻找从化学数据库中使用R,主要是name
,CAS Number
和molecular weight
现在刮一些数据。但是,我无法获取rvest
来提取我正在查找的信息。这是我到目前为止的代码:Rvest web scrape返回空字符
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"
,但都没有给我我正在寻找的东西。
您正试图让'Depositor-Supplied Synonyms'正确吗? – AK88
上面的例子只是试图检索主页上的物质名称,但如果可能的话,我也希望检索存款人提供的同义词。 –