【问题标题】:Selecting title within h3 class - Css Selector using rvest在 h3 类中选择标题 - 使用 rvest 的 Css 选择器
【发布时间】:2018-01-10 21:31:16
【问题描述】:

我正在尝试使用 R 中的 rvest 包和 SelectorGadget 提取标题描述,以识别我的 CSS 选择器。

<div class="detail">
<h3 class="">                                                                                       
<a href="[].html" 
title="Vasyl Lomachenko Beats Guillermo Rigondeaux" 
class="">Madison Square Garden...</a>

当前使用以下代码选择 h3 类数据:“麦迪逊广场花园...”。我想选择标题数据,即“Vasyl Lomachenko Beats Guillermo Rigondeaux”。

url <- 'www.url.com'
webpage <- read_html(url)
Desc <- html_nodes(webpage,'h3') %>% html_text()

我在下面提到了这个问题,但仍然无法解决。非常欢迎任何帮助!

Scraping image titles with rvest

【问题讨论】:

  • 网站是 boxrec。他们没有 robots.txt,没有 T&C/ToS。其他抓取工具似乎从他们那里收集数据,所以我天真地认为也可以收集信息。此外,我收集的数据是为了开发一个个人项目。我想看看偏离平均战斗重量的拳击手是否或多或少地击败了他们的对手。但是,我同意我应该与网站管理员核实是否允许收集此信息。感谢您的反馈,并不意味着将您拖入道德冲突。 boxrec.com/media/index.php/…

标签: r css-selectors rvest


【解决方案1】:

超级简单,之前没用过html_attr:

webpage %>% html_nodes("h3 a") %>% html_attr("title")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 2018-06-02
    • 2018-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    相关资源
    最近更新 更多