【问题标题】:Rvest returns zero listRvest 返回零列表
【发布时间】:2019-03-03 23:00:01
【问题描述】:

我想使用 rvest 从网上下载论文的所有链接/标题。我使用了以下脚本,但它不是列表为零。有什么建议?

图书馆(rvest)

1。下载 HTML 并使用 read_html() 将其转换为 XML 文件

论文https://papers.ssrn.com/sol3/JELJOUR_Results.cfm?npage=1&form_name=journalBrowse&journal_id=1475407&Network=no&lim=false")

2。使用 html_nodes() 提取特定节点

标题

【问题讨论】:

    标签: rvest webharvest


    【解决方案1】:

    你很接近,试试.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
    

    reprex package (v0.2.1) 于 2018 年 9 月 28 日创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 2021-07-31
      相关资源
      最近更新 更多