【发布时间】:2018-01-20 23:16:05
【问题描述】:
我目前正在开展一个使用 R 处理网络抓取的项目。 这是非常基本的,但我试图了解它是如何工作的。
我使用 Google Stocks 作为我的 URL,我使用 Google 股票代码作为我正在查看的股票。
这是我的代码:
# Declaring our URL variable
google = html("https://www.google.com/searchq=google+stock%5D&oq=google+stock%5D&aqs=chrome..69i57j0l2j69i60l3.5208j0j4&sourceid=chrome&ie=UTF-8")
# Prints and initializes the data
google_stock = google %>%
html_nodes("._FOc , .fac-l") %>%
html_text()
# Creating a data frame table
goggledf = data.frame(table(google_stock))
# Orders the data into highest frequency shown
googledf_order = googledf[order(-googledf$Freq),]
# Displays first few rows of data
head(googledf_order)
当我运行它时,我得到integer(0),它应该显示股票价格。
我不确定为什么这没有显示正确的股票价格。
我还尝试运行代码直到html_text(),但它仍然没有向我显示我想要或需要的数据。
我只需要这个来显示网络上的股票价格。
我正在使用 SelectorGadget 获取我的 html 节点(“._FOc , .fac-l”)
【问题讨论】:
标签: r web-scraping