【问题标题】:Extraction of specific fields from a thread in a forum从论坛中的线程中提取特定字段
【发布时间】:2011-07-27 22:56:41
【问题描述】:

我正在从事一个数据挖掘项目,我需要为此分析论坛主题中的讨论进度。我有兴趣提取发布时间、帖子作者的统计信息(帖子数量、加入日期等)、帖子文本等信息。

但是,在使用标准抓取工具(如 python 中的 Scrapy)时,我需要编写正则表达式来检测页面 html 源代码中的这些字段。由于这些标签因论坛类型而异,因此处理每个论坛的正则表达式已成为一个主要问题。是否有可用的此类正则表达式的标准库,以便可以根据论坛类型使用它们?

或者是否有任何其他技术可以从论坛页面中提取这些字段。

【问题讨论】:

    标签: python regex web-scraping scrapy forums


    【解决方案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 是包含所有线程链接的 div 线程是您可以找到每个线程的链接的地方 list_next_page 是指向具有线程列表的下一页的链接 post 是带有帖子文本的 div。 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
    

    【讨论】:

      【解决方案2】:

      您仍然需要为每个论坛创建多种方法。但正如 Henley 所说,也有很多论坛共享它们的结构。

      关于轻松解析论坛帖子的日期,dateparser 就是从这个特定的要求中诞生的,它可能会有很大的帮助。

      【讨论】:

      • 一个问题:Henley Chiu 配置是否仍能满足我们在 Vbulletin 版本 3.8.10 中面临的需求 - 我需要解决这个问题:我需要找到所有线程(包含某个帖子的帖子) user) 在以下结构中可见 soup = bs.BeautifulSoup(html, 'html.parser') 和 threads = soup.find_all('tr', attrs={'class' : 'alt1'}) 。这样做 - 我需要收集所有线程 - 在许多页面上...... - 可行
      猜你喜欢
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      相关资源
      最近更新 更多