我想獲取在R.使用rvest從谷歌新聞頭條,到目前爲止如何使用rvest R從谷歌新聞獲取標題?
library(rvest)
url=read_html("https://www.google.com/search?hl=en&tbm=nws&authuser=0&q=american+president")
selector_name<-"r"
fnames<-html_nodes(x = url, css = selector_name) %>%
html_text()
我已經這樣做了,但結果是
> fnames
character(0)
這是檢查標題的元素嗎?
<h3 class="r"><a href="/browse.php/PbtvpluS/QDvUJpC7/KoWCA9QE/VTTOFmVJ/bIp8sMa8/qKjgkcAu/Hgcr9lyg/4bibGCOO/nZ82ojLo/_2B602Vo/0sOSEbba/SaiySebj/AqD60GRO/skpNXIW9/fA8EbzOq/z6XjMXo2/9iDad2zD/qREp_2Fp/hoHl64rG/9wfBHOPB/a0nLFrAz/OsCmtfKV/cQoDAFWY/cRXfd5FX/5OAJF8UR/9gUdG_2F/_2F4hOLN/xOfe6_2F/shH2n9O7/hCZGQosp/eeAh6wAC/JhCOgG0i/sLkpRGRN/PH_2B61L/njabdbV1/vpS4wcbX/NKpO_2Bq/jpun2LeG/TQecIESv/vxFbk19Q/_3D_3D/b29/">Obama Addresses Racial Tensions at Celebration of African ...</a></h3>
如何從Google新聞中獲取標題?
這可能比較容易抓住RSS提要。有一個['feedeR'](https://cran.rstudio.com/web/packages/feede/index.html)包,看起來只需要一個URL來提取數據。 – alistaire