0

我正在使用 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")
4

2 回答 2

0

如果您正在寻找类似数据框的结构,这就是您创建它的方式(注意:并非所有字段都从语料库中提取):

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 Hadoop\nHow businesses can realise and capitalise on the opportunities that Hadoop offers\nPosted b"| __truncated__ "By Stephanie Simon\n1/11/15 6:32 PM EST\nPresident Barack Obama on Monday is expected to call for tough legislation to protect "| __truncated__ "By Adam                             Courtenay\nData mining is now viewed as a serious security threat, but with all the hype, s"| __truncated__ "How We Buy\nJanuary 12, 2015\nTesco, 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

如果你想要/需要其他东西,你需要在你的问题中更清楚。

于 2015-02-04T20:59:12.470 回答
0

我正在查看 google 查询字符串,并注意到如果您单击页面右侧的日期,它们会在查询中传递 startdate 和 enddate 标记。

您可以使用相同的标签名称,并且您的结果将被限制在开始和结束日期内。

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'))
于 2015-10-27T10:05:59.620 回答