Web scraping 非结构化数据的网络爬虫

Web scraping 非结构化数据的网络爬虫,web-scraping,scrapy,web-crawler,nlp,Web Scraping,Scrapy,Web Crawler,Nlp,有没有适合解析许多非结构化网站(新闻、文章)并在没有预先定义规则的情况下从中提取主要内容块的网络爬虫 我的意思是,当我解析新闻提要时,我想从每篇文章中提取主要内容块来做一些NLP工作。我有很多网站,要研究它们的DOM模型并为每个模型编写规则需要花费很长时间 我试着使用Scrapy来获取所有文本,不带标签和脚本,放在一个正文中,但是它包含很多不相关的东西,比如菜单项、广告块等等 site_body = selector.xpath('//body').extract_first() 但对此类内容

有没有适合解析许多非结构化网站(新闻、文章)并在没有预先定义规则的情况下从中提取主要内容块的网络爬虫

我的意思是,当我解析新闻提要时,我想从每篇文章中提取主要内容块来做一些NLP工作。我有很多网站,要研究它们的DOM模型并为每个模型编写规则需要花费很长时间

我试着使用Scrapy来获取所有文本,不带标签和脚本,放在一个正文中,但是它包含很多不相关的东西,比如菜单项、广告块等等

site_body = selector.xpath('//body').extract_first()
但对此类内容进行NLP将不会非常精确


那么有没有其他的工具或方法来完成这些任务呢?

我试着用它来解决这个问题。因此,您可以对网页本身的源代码进行注释,并将其用作匹配的示例,而无需编写特殊规则

例如,如果查看此页面的源代码,您会看到:

<td class="postcell">
<div>
    <div class="post-text" itemprop="text">

<p>Are there any web-crawlers adapted for parsing many unstructured websites (news, articles) and extracting a main block of content from them without previously defined rules?</p>
(通常您也需要结束标记,但对于单个元素,则不需要结束标记)

然后将该模式传递给Xidel(因此似乎阻止了默认的用户代理,因此需要对其进行更改)


您可以在
parse()
get_text()
中使用漂亮的汤:

您还可以手动删除不需要的内容(如果您发现喜欢某些标记,例如,
可能是有用的信号)


您可以做类似的事情,将一些标签列入白名单。

您尝试过可视化方法吗?我建议使用这种方法进行检查,您仍然需要定义所有这些div块及其ID。不为数百个网站工作。想法是,你不必写它们,只需从网页上复制它们。我对200多个图书馆网页使用这种方法
<td class="postcell">
<div>
<div class="post-text" itemprop="text">
{.}
xidel 'http://stackoverflow.com/questions/36066030/web-crawler-for-unstructured-data' --user-agent "Mozilla/5.0 (compatible; Xidel)"  -e '<td class="postcell"><div><div class="post-text" itemprop="text">{.}'
Are there any web-crawlers adapted for parsing many unstructured websites (news, articles) and extracting a main block of content from them without previously defined rules?

I mean when I'm parsing a news feed, I want to extract the main content block from each article to do some NLP stuff. I have a lot of websites and it will take forever to look into their DOM model and write rules for each of them.

I was trying to use Scrapy and get all text without tags and scripts, placed in a body, but it include a lot of un-relevant stuff, like menu items, ad blocks, etc.

site_body = selector.xpath('//body').extract_first()


But doing NLP over such kind of content will not be very precise.

So is there any other tools or approaches for doing such tasks?
from bs4 import BeautifulSoup, Comment

soup = BeautifulSoup(response.body, 'html.parser')

yield {'body': soup.get_text() }
# Remove invisible tags
#for i in soup.findAll(lambda tag: tag.name in ['script', 'link', 'meta']):
#     i.extract()