0
我想从联合国粮农组织网站(http://www.fao.org/countryprofiles/en/)建立一个数据集。 在此页面中包含一组指向国家的链接。 点击此链接的任何一个链接将导致包含国家/地区新闻的特定国家/地区的页面。 这个想法是在数据集包括:R网络扫描数据集
Country name
Country url (e.g. <http://www.fao.org/countryprofiles/index/en/?iso3=AFG>)
News url (e.g. <http://www.fao.org/afghanistan/news/detail-events/en/c/1045264/>)
News title (e.g. World Food Day 2017 Celebrations in Afghanistan)
News date (e.g. 17/11/2017)
然而,我也做了以下内容:
## Import web page
FAO_Countries <- read_html("http://www.fao.org/countryprofiles/en/")
## Import the urls I am interested in with 'selectorgadget'
FAO_Countries_urls <- FAO_Countries %>%
html_nodes(".linkcountry") %>%
html_attr("href")
## Import the links I am interested in with 'selectorgadget'
FAO_Countries_links <- FAO_Countries %>%
html_nodes(".linkcountry") %>%
html_text()
## I create a dataframe with two previous objects
FAO_Countries_data <- data.frame(FAO_Countries_links=FAO_Countries_links,
FAO_Countries_urls = FAO_Countries_urls, stringsAsFactors = FALSE)
我应该如何进行?
你应该:a)列出你已经装包,和b)表明你有什么困难。 –
1.包: rvest, stringr, tidyr, data.table, plyr, XML2。 2.我无法获取新闻和新闻日期 – Ileeo