我正在使用 R 包tm.plugin.webmining
。使用函数GoogleNewsSource()
我想查询按日期和特定日期排序的新闻。有没有查询特定日期新闻的参数?
library(tm)
library(tm.plugin.webmining)
searchTerm <- "Data Mining"
corpusGoog <- WebCorpus(GoogleNewsSource(params=list(hl="en", q=searchTerm,
ie="utf-8", num=10, output="rss" )))
headers <- meta(corpusGoog,tag="datetimestamp")
如果您正在寻找类似数据框的结构,那么创建它的方式就是这样(注意:并非所有字段都从语料库中提取):
library(dplyr)
make_row <- function(elem) {
data.frame(timestamp=elem[[2]]$datetimestamp,
heading=elem[[2]]$heading,
description=elem[[2]]$description,
content=elem$content,
stringsAsFactors=FALSE)
}
dat <- bind_rows(lapply(corpusGoog, make_row))
str(dat)
## Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 10 obs. of 4 variables:
## $ timestamp : POSIXct, format: "2015-02-03 13:08:16" "2015-01-11 23:37:45" ...
## $ heading : chr "A guide to data mining with Hadoop - Information Age" "Barack Obama to seek limits on student data mining - Politico" "Is data mining riddled with risk or a natural hazard of the internet? - INTHEBLACK" "Why an obscure British data-mining company is worth $3 billion - Quartz" ...
## $ description: chr "Information AgeA guide to data mining with HadoopInformation AgeWith the advent of the Internet of Things and the transition fr"| __truncated__ "PoliticoBarack Obama to seek limits on student data miningPoliticoPresident Barack Obama on Monday is expected to call for toug"| __truncated__ "INTHEBLACKIs data mining riddled with risk or a natural hazard of the internet?INTHEBLACKData mining is now viewed as a serious"| __truncated__ "QuartzWhy an obscure British data-mining company is worth $3 billionQuartzTesco, the troubled British retail group, is starting"| __truncated__ ...
## $ content : chr "A guide to data mining with HadoopnHow businesses can realise and capitalise on the opportunities that Hadoop offersnPosted b"| __truncated__ "By Stephanie Simonn1/11/15 6:32 PM ESTnPresident Barack Obama on Monday is expected to call for tough legislation to protect "| __truncated__ "By Adam CourtenaynData mining is now viewed as a serious security threat, but with all the hype, s"| __truncated__ "How We BuynJanuary 12, 2015nTesco, the troubled British retail group, is starting over. After an accounting scandal , a serie"| __truncated__ ...
然后,您可以做任何您想做的事情。例如:
dat %>%
arrange(timestamp) %>%
select(heading) %>%
head
## Source: local data frame [6 x 1]
##
## heading
## 1 The potential of fighting corruption through data mining - Transparency International (pre
## 2 Barack Obama to seek limits on student data mining - Politico
## 3 Why an obscure British data-mining company is worth $3 billion - Quartz
## 4 Parks and Rec Recap: Treat Yo Self to Some Data Mining - Indianapolis Monthly
## 5 Fraud and data mining in Vancouverâu0080¦just Outside the Lines - Vancouver Sun (blog)
## 6 'Parks and Rec' Data-Mining Episode Was Eerily True To Life - MediaPost Communications
如果你想要/需要别的东西,你需要在你的问题中更清楚。
我正在查看谷歌查询字符串,并注意到如果您单击页面右侧的日期,它们会在查询中传递开始日期和结束日期标签。
您可以使用相同的标签名称,并且您的结果将限制在开始和结束日期内。
GoogleFinanceSource(query, params = list(hl = "en", q = query, ie = "utf-8",
start = 0, num = 25, output = "rss",
startdate='2015-10-26', enddate = '2015-10-28'))