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