【问题标题】:Rvest getting an specific text from html_nodeRvest 从 html_node 获取特定文本
【发布时间】:2019-05-29 21:30:27
【问题描述】:

我只想提取“Beech Valley Solutions -”

当我跑步时

html_nodes('li') %>% 
  html_nodes(".flexbox.empLoc") %>%  
  html_text() 

所有信息都出来了。 “Beech Valley Solutions - 佐治亚州亚特兰大今天 24 小时”

【问题讨论】:

  • 请将 HTML 添加为文本而不是屏幕截图,因为图像不是可搜索的文本
  • 可以给我们测试的url吗?

标签: html r web-scraping rvest


【解决方案1】:

还有另一种使用 rvest 进行 scraping 的方法。 您可以在 html_nodes() 中传递 xpath,而不是在 html_nodes() 中传递 css 选择器项。下面只是一个示例 -

page %>% html_nodes(xpath = "//*[@id='series-matches']/div[20]/div[3]/div[1]/a[1]/span")

参考: https://blog.rstudio.com/2014/11/24/rvest-easy-web-scraping-with-r/

x 路径更容易获取 -

  1. 右键单击要获取 xpath 的部分。
  2. 从下拉列表中选择检查代码。 3. html页面会出现在右侧,点击右键点击复制选项。
  3. 会出现Drop,从中选择“Copy xpath”。
  4. Ctrl V(粘贴)在 html_nodes(xpath = "xpath here")中的 xpath。希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    相关资源
    最近更新 更多