Rvest возвращает нулевой список - PullRequest
0 голосов
/ 28 сентября 2018

Я хочу скачать все ссылки / названия статей из Интернета, используя rvest.Я использовал следующий скрипт, но это не список ноль.Какие-либо предложения?

библиотека (rvest)

1.Загрузите HTML-код и превратите его в файл XML с помощью read_html ()

Papers <- read_html ("<a href="https://papers.ssrn.com/sol3/JELJOUR_Results.cfm?npage=1&form_name=journalBrowse&journal_id=1475407&Network=no&lim=false" rel="nofollow noreferrer">https://papers.ssrn.com/sol3/JELJOUR_Results.cfm?npage=1&form_name=journalBrowse&journal_id=1475407&Network=no&lim=false")

2. Извлеките определенные узлы с помощью html_nodes ()

Заголовки <- html_nodes (Papers, "span.optClickTitle") </p>

1 Ответ

0 голосов
/ 28 сентября 2018

Вы близки, попробуйте .optClickTitle вместо span.optClickTitle:

library(magrittr)
library(tibble)
library(rvest)
#> Lade nötiges Paket: xml2

url <- "https://papers.ssrn.com/sol3/JELJOUR_Results.cfm?npage=1&form_name=journalBrowse&journal_id=1475407&Network=no&lim=false"
raw <- read_html(url)

parse_link <- function(x) {
  tibble(title = html_text(x),
         link = html_attr(x = x, name = "href"))
}

raw %>%
  html_nodes(".optClickTitle") %>%
  parse_link()
#> # A tibble: 60 x 2
#>    title                                            link                  
#>    <chr>                                            <chr>                 
#>  1 The Nature of Man                                https://ssrn.com/abst…
#>  2 The Dynamics of Crowdfunding: An Exploratory St… https://ssrn.com/abst…
#>  3 Some Simple Economics of the Blockchain          https://ssrn.com/abst…
#>  4 "Some Simple Economics of the Blockchain\r\n\t\… https://ssrn.com/abst…
#>  5 "Some Simple Economics of the Blockchain\r\n\t\… https://ssrn.com/abst…
#>  6 Bitcoin: An Innovative Alternative Digital Curr… https://ssrn.com/abst…
#>  7 Piracy and Box Office Movie Revenues: Evidence … https://ssrn.com/abst…
#>  8 The sharing economy: Why people participate in … https://ssrn.com/abst…
#>  9 Consumer Acceptance and Use of Information Tech… https://ssrn.com/abst…
#> 10 What Makes Online Content Viral?                 https://ssrn.com/abst…
#> # ... with 50 more rows

Создано в 2018-09-28 пакетом Представления (v0.2.1)

...