Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从论坛中的线程提取特定字段_Python_Regex_Web Scraping_Scrapy_Forums - Fatal编程技术网

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

Python 从论坛中的线程提取特定字段,python,regex,web-scraping,scrapy,forums,Python,Regex,Web Scraping,Scrapy,Forums,我正在做一个数据挖掘项目,我需要在论坛上分析讨论的进展情况。我对提取信息感兴趣,比如发帖时间、发帖作者的统计信息(发帖数量、加入日期等)、发帖文本等 然而,在使用标准的抓取工具(如python中的Scrapy)时,我需要编写正则表达式来检测页面html源中的这些字段。由于这些标签随论坛类型的不同而不同,因此处理每个论坛的正则表达式成为一个主要问题。是否有这样的正则表达式的标准库,以便根据论坛的类型使用它们 或者是否有其他技术可以从论坛页面中提取这些字段。我为一些主要论坛编写了一些配置文件。希望你

我正在做一个数据挖掘项目,我需要在论坛上分析讨论的进展情况。我对提取信息感兴趣,比如发帖时间、发帖作者的统计信息(发帖数量、加入日期等)、发帖文本等

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


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

我为一些主要论坛编写了一些配置文件。希望你能破译并推断出如何解析它

对于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;>
封闭的_部分是包含所有线程链接的div 线程是您可以找到每个线程的链接的地方 list_next_page是指向下一页的链接,其中包含线程列表 post是带有post文本的div。 线程下一页是指向线程下一页的链接

对于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

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


关于轻松解析论坛线程的日期,这是从这一特定需求中产生的,可能会有很大帮助。

一个问题:Henley Chiu的配置是否仍能满足我们在Vbulletin 3.8.10版中面临的需求?我需要解决这个问题:我需要找到所有线程(包含某个用户的帖子)可以在以下结构中看到:soup=bs.BeautifulSoup(html,'html.parser')和threads=soup.find_all('tr',attrs={'class':'alt1'})。这样做-我需要收集所有的线索-在许多页面上…-可行