Web Scrape不会返回正确的文本数据

问题描述 投票:0回答:1

我正试图逃离二手歌曲网站上的简单表格。我在R中使用以下代码和qazxsw poi包

rvest

哪个回报

library(tidyverse)
library(rvest)

levee_breaks_url <- html('https://secondhandsongs.com/performance/17982')

levee_breaks_url %>% 
  html_node('.field-performer') %>% 
  html_text()

我的目标是获取页面上表格中所有信息的列表。我试过包括[1] "Performer " ,但结果不正确。

我正在使用html_node('.container')并且在抓取其他网站方面取得了成功,但我已经坚持了一段时间。

r web-scraping tidyverse rvest
1个回答
3
投票

试一试。这将刮掉所有表,合并它们,然后为列提供正确的名称。

selector gadget

library(tidyverse) library(rvest) levee_breaks_url <- read_html('https://secondhandsongs.com/performance/17982') df <- levee_breaks_url %>% html_nodes('.table') %>% html_table() %>% reduce(rbind) %>% select(-1) %>% rename_all(~levee_breaks_url %>% html_nodes('th') %>% html_text() %>% .[2:5]) %>% as.tibble() df #> # A tibble: 32 x 4 #> `Title ` `Performer ` `Release date ` Info #> <chr> <chr> <chr> <chr> #> 1 When the Leve… Kansas Joe and Memp… 1929 First release #> 2 When the Leve… John Campbell February 20, 19… "" #> 3 When the Leve… Clint Black 2005 "" #> 4 When the Leve… Bennett Harris August 27, 2008 "" #> 5 When the Leve… Buckwheat Zydeco 2009 "" #> 6 Levee Breaks Beverley Martyn April 2014 "" #> 7 When the Leve… Danny B. Harvey - M… October 14, 2014 "" #> 8 When the Leve… Led Zeppelin November 8, 1971 First releaseSamp… #> 9 When the Leve… Judge 1990 "" #> 10 When the Leve… Rosetta Stone October 14, 1991 Unverified #> # ... with 22 more rows 创建于2018-09-06(v0.2.0)。

© www.soinside.com 2019 - 2024. All rights reserved.