Css 无法在rvest中标识用于刮取的html节点
试图从页面抓取链接以进行后续分析,只能抓取其中大约1/2的链接,这可能是由于过滤造成的。我试图提取此处突出显示的链接: 我的方法如下,这并不理想,因为我相信我可能会丢失Css 无法在rvest中标识用于刮取的html节点,css,r,screen-scraping,rvest,Css,R,Screen Scraping,Rvest,试图从页面抓取链接以进行后续分析,只能抓取其中大约1/2的链接,这可能是由于过滤造成的。我试图提取此处突出显示的链接: 我的方法如下,这并不理想,因为我相信我可能会丢失filter()调用中的一些链接 library(rvest) library(tidyverse) #initiate session session <- html_session("https://www.backlisted.fm/episodes") #collect links for
filter()
调用中的一些链接
library(rvest)
library(tidyverse)
#initiate session
session <- html_session("https://www.backlisted.fm/episodes")
#collect links for all episodes from the index page:
session %>%
read_html() %>%
html_nodes(".underline-body-links a") %>%
html_attr("href") %>%
tibble(link_temp = .) %>%
filter(str_detect(link_temp, pattern = "episodes/")) %>%
distinct()
#css:
#.underline-body-links #page .html-block a, .underline-body-links #page .product-excerpt ahere
#result:
link_temp
<chr>
1 /episodes/116-mfk-fisher-how-to-cook-a-wolf
2 https://www.backlisted.fm/episodes/109-barbara-pym-excellent-women
3 /episodes/115-george-amp-weedon-grossmith-the-diary-of-a-nobody
4 https://www.backlisted.fm/episodes/27-jane-gardam-a-long-way-from-verona
5 https://www.backlisted.fm/episodes/5-b-s-johnson-christie-malrys-own-double-entry
6 https://www.backlisted.fm/episodes/97-ray-bradbury-the-illustrated-man
7 /episodes/114-william-golding-the-inheritors
8 https://www.backlisted.fm/episodes/30-georgette-heyer-venetia
9 https://www.backlisted.fm/episodes/49-anita-brookner-look-at-me
10 https://www.backlisted.fm/episodes/71-jrr-tolkien-the-return-of-the-king
# … with 43 more rows
库(rvest)
图书馆(tidyverse)
#启动会话
会话%
读取html()%>%
html_节点(“.underline body links a”)%>%
html_attr(“href”)%%>%
TIBLE(链接温度=)%>%
过滤器(str_detect(link_temp,pattern=“scents/”))%>%
不同的()
#css:
#.underline body links#page.html block a、.underline body links#page.产品摘录a
#结果:
链路温度
1/集/116-mfk-fisher-how-to-cook-a-wolf
2.https://www.backlisted.fm/episodes/109-barbara-pym-excellent-women
3/集/115-george-amp-weedon-grossmith-the-diary-of-a-nobody
4.https://www.backlisted.fm/episodes/27-jane-gardam-a-long-way-from-verona
5.https://www.backlisted.fm/episodes/5-b-s-johnson-christie-malrys-own-double-entry
6.https://www.backlisted.fm/episodes/97-ray-bradbury-the-illustrated-man
7/14集/114威廉·戈尔丁继承人
8.https://www.backlisted.fm/episodes/30-georgette-heyer-venetia
9https://www.backlisted.fm/episodes/49-anita-brookner-look-at-me
10https://www.backlisted.fm/episodes/71-jrr-tolkien-the-return-of-the-king
#…还有43行
我已经阅读了多个文档,但我不能针对这一类型的href。任何帮助都将不胜感激。谢谢。试试这个
library(rvest)
library(tidyverse)
session <- html_session("https://www.backlisted.fm/index")
raw_html <- read_html(session)
node <- raw_html %>% html_nodes(css = "li p a")
link <- node %>% html_attr("href")
title <- node %>% html_text()
tibble(title, link)
# A tibble: 117 x 2
# title link
# <chr> <chr>
# 1 "A Month in the Country" https://www.backlisted.fm/episodes/1-j-l-carr-a-month-in-the-country
# 2 " - J.L. Carr (with Lissa Evans)" #
# 3 "Good Morning, Midnight - Jean Rhys" https://www.backlisted.fm/episodes/2-jean-rhys-good-morning-midnight
# 4 "It Had to Be You - David Nobbs" https://www.backlisted.fm/episodes/3-david-nobbs-1
# 5 "The Blessing - Nancy Mitford" https://www.backlisted.fm/episodes/4-nancy-mitford-the-blessing
# 6 "Christie Malry's Own Double Entry - B.S. Joh… https://www.backlisted.fm/episodes/5-b-s-johnson-christie-malrys-own-dou…
# 7 "Passing - Nella Larsen" https://www.backlisted.fm/episodes/6-nella-larsen-passing
# 8 "The Great Fire - Shirley Hazzard" https://www.backlisted.fm/episodes/7-shirley-hazzard-the-great-fire
# 9 "Lolly Willowes - Sylvia Townsend Warner" https://www.backlisted.fm/episodes/8-sylvia-townsend-warner-lolly-willow…
# 10 "The Information - Martin Amis" https://www.backlisted.fm/episodes/9-martin-amis-the-information
# … with 107 more rows
库(rvest)
图书馆(tidyverse)
会话精彩谢谢-我也很感谢额外的分离,包括标题