我正在嘗試抓取基于 html 的期刊文章的特定部分。例如,如果我只想抓取 Frontiers 出版物中文章的“統計分析”部分,我該怎么做?由于每篇文章的段落數量和部分位置都會發生變化,因此 selectorGadget 沒有幫助。
https://www.frontiersin.org/articles/10.3389/fnagi.2010.00032/full
我已經嘗試將 rvest 與 html_nodes 和 xpath 一起使用,但我沒有任何運氣。我能做的最好的就是從我想要的部分開始刮,但不能讓它停止。有什么建議?
example_page <- "https://www.frontiersin.org/articles/10.3389/fnagi.2010.00032/full"
example_stats_section <- read_html(example_page) %>%
html_nodes(xpath="//h3[contains(., 'Statistical Analyses')]/following-sibling::p") %>%
html_text()
uj5u.com熱心網友回復:
由于每次“統計分析”嘗試后都有一個“結果”部分
//h3[.='Statistical Analyses']/following-sibling::p[following::h2[.="Results"]]
獲取所需部分
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/424258.html
