html - 如何获取选择菜单的值?
问题描述
我正在尝试获取此网页上选择菜单的值(所有区域) 。我有什么错?几乎尝试了所有组合,但结果为零。其中之一是:
page <- read_html("https://www.yemeksepeti.com/en/istanbul")
regions <- page %>%
html_nodes("div") %>%
html_nodes("span") %>%
html_nodes(xpath = '//*[@id="select2-ys-areaSelector-container"]') %>%
html_attr("title")
提前致谢。
解决方案
XPath 是一种丑陋的野兽。获取select
元素的 id,然后获取所有选项组,最后获取它们的文本数据。用于html_text
将其转换为 R character
。
page <- read_html("https://www.yemeksepeti.com/en/istanbul")
regions <- page %>%
html_nodes(xpath='//*[@id="ys-areaSelector"]/optgroup/*/text()') %>%
html_text()
推荐阅读
- .net - Azure Function 和自托管 SignalR 服务器
- maps - 使用 OSM 数据到 pwa
- android - 使用 Google 发布 API 修改版本的发行说明
- xml - XML 中值的特定部分/字符
- java - 模拟一个弹簧接口
- java - 如何在 Java 中实现 addFields mongoDB 查询
- node.js - 如果我对一个弹出另一个错误进行排序,则会显示两个错误 TypeError: cart is not a constructor in post method and cart.find is not a function
- excel - ORA-12560:TNS:协议适配器错误问题:Excel 64 位/Windows 10 64 位
- javascript - 选定天数随机排序,查找最早和最晚
- c# - 为什么持有类对象引用的接口类型变量不调用类成员函数?