从论坛线程中提取特定字段

0 投票
2 回答
1019 浏览
提问于 2025-04-16 14:55

我正在做一个数据挖掘的项目,需要分析论坛中讨论的进展。我想提取一些信息,比如发帖时间、发帖人的统计信息(比如发帖数量、加入日期等)、帖子内容等等。

不过,当我使用一些常规的抓取工具(比如Python中的Scrapy)时,我需要为页面的HTML源代码编写正则表达式,以便找到这些信息。因为不同论坛的标签格式各不相同,所以每个论坛都要处理不同的正则表达式,这让我感到很头疼。有没有什么标准的正则表达式库可以用,方便根据论坛类型来使用呢?

或者有没有其他方法可以从论坛页面提取这些信息。

2 个回答

1

你还是需要为每个论坛创建几种不同的方法。不过正如Henley所说,很多论坛的结构是相似的。

关于如何轻松解析论坛帖子中的日期,dateparser就是为了满足这个需求而诞生的,它可能会对你大有帮助。

1

我为一些大型论坛写了一些配置文件。希望你能理解并推断出如何解析它。

对于VBulletin:

enclosed_section=tag:table,attributes:id;threadslist
thread=tag:a,attributes:id;REthread_title_
list_next_page=type:next_page,attributes:anchor_text;>
post=tag:div,attributes:id;REpost_message_
thread_next_page=type:next_page,attributes:anchor_text;>

enclosed_section是一个包含所有主题链接的区域;thread是你可以找到每个主题链接的地方;list_next_page是指向下一个包含主题列表的页面的链接;post是包含帖子内容的区域;thread_next_page是指向该主题下一个页面的链接。

对于Invision:

enclosed_section=tag:table,attributes:id;forum_table
thread=tag:a,attributes:class;topic_title
list_next_page=tag:a,attributes:rel;next,inside_tag_attribute:href
post=tag:div,attributes:class;post entry-content |
thread_next_page=tag:a,attributes:rel;next,inside_tag_attribute:href
post_count_section=tag:td,attributes:class;stats
post_count=tag:li,attributes:,reg_exp:(\d+) Repl

撰写回答