【发布时间】:2023-11-22 08:20:01
【问题描述】:
我希望使用 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",但都没有给我我想要的东西。
【问题讨论】:
-
你想得到
Depositor-Supplied Synonyms对吗? -
上面的例子只是试图在主页上检索物质名称,但如果可能的话,我也想检索 Depositor-Supplied Synonyms。
标签: r web-scraping rvest pubchem