我正在尋找從化學數據庫中使用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
上面的例子只是試圖檢索主頁上的物質名稱,但如果可能的話,我也希望檢索存款人提供的同義詞。 –