gpt4 book ai didi

r - 如何使用 rvest 从基于网络的论坛中抓取消息

转载 作者:行者123 更新时间:2023-12-01 08:54:59 25 4
gpt4 key购买 nike

以示例中的 vbulletin 站点为例。
我希望能够仅从线程中抓取文本消息。但是,消息的 css 选择器称为 #post_message_xxx,其中 xxx 是可变 ID 号。

如何将选择器与 html_nodes 部分匹配,以便我获得所有以 #post_message 开头的选择器,而不管它们如何结束?

或者也许我应该问一个更一般的问题。如果我希望能够将作者归因于消息并跟踪消息顺序,我应该如何抓取页面。

谢谢。

library(rvest)
html <- html("http://www.acme.com/forums/new_rules_28429/")
cast <- html_nodes(html, "#post_message_28429")
cast

> <div id="post_message_28429">&#13; &#13; Thanks for posting
> this.&#13; </div>
>
> attr(,"class")

[1] "XMLNodeSet"

最佳答案

不要使用 css 选择器,而是使用带有 starts-with() 的 xpath 选择器。功能

cast <- html_nodes(html, xpath="//div[starts-with(@id,'post_message')]")

关于r - 如何使用 rvest 从基于网络的论坛中抓取消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28801456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com