【发布时间】:2019-09-07 11:03:36
【问题描述】:
我有 .rtf 格式的文章,我想从中提取日期。文章长这样:
第一行是标题,后面是一个空行。然后它列出了以下内容,每个都在自己的行中:
- 字数
- 日期
- 通讯社
- 通讯社的缩写
- 语言
- 版权信息
我已经尝试了以下代码,但它似乎不起作用。似乎问题在于提取日期。
##First I read the file using this code:
htmlText <- read_file(paste("/Users/adhyantarahma/Desktop/Factiva-20190905-0316.rtf"))
##then I removed new lines tags
removeNewLines <- gsub("\n"," ",htmlText)
##and I changed " to ' in text
cleanLines <- gsub("\"", "'", removeNewLines)
print(cleanLines)
##the relevant part of cleanLines look like this
#\\ 347 words\\ 9 April 2016\\ FARS News Agency\\ FARSNA\\ English\\
##then I used this to extract date
date <- str_extract_all(htmlText, "words \\d{1,2} [A-Z][a-z]+ \\d{4}")[[1]]
但它似乎没有选择日期。当我运行它时,它总是说没有字符。
我应该怎么做才能取到日期?
【问题讨论】: