文章提取器,Web Scrapping for Python3

goose3的Python项目详细描述


https://travis-ci.org/goose3/goose3.svg?branch=masterhttps://badge.fury.io/py/goose3.svg

简介

goose最初是一个用java编写的文章提取器,它拥有 最近(2011年8月)被转换为scala project

这是python中的完全重写。软件的目的是 获取任何新闻文章或文章类型的网页,而不仅仅是提取 是本文的主体,也是所有元数据和最可能的 形象候选人。

goose将尝试提取以下信息:

  • 文章的正文
  • 文章的主要图像
  • 文章中嵌入的任何YouTube/Vimeo电影
  • 元描述
  • 元标记

python版本最初由以下人员重写:

  • 泽维尔格兰杰

许可

如果你觉得鹅有用或有问题,请给我一个电话。我很乐意 来了解你是如何使用它的,或者应该改进哪些功能。

goose是由gravity.com根据apache 2.0许可证授权的;请参阅 有关详细信息,请参阅许可证文件。

联机文档

联机文档位于 Read the Docs包含更深入的内容 文档。

设置

使用pip安装:

pip install goose3

从源安装:

mkvirtualenv --no-site-packages goose3
git clone https://github.com/goose3/goose3.git
cd goose3
pip install -r ./requirements/python
python setup.py install

转一圈

>>>fromgoose3importGoose>>>url='http://edition.cnn.com/2012/02/22/world/europe/uk-occupy-london/index.html?hpt=ieu_c2'>>>g=Goose()>>>article=g.extract(url=url)>>>article.titleu'Occupy London loses eviction fight'>>>article.meta_description"Occupy London protesters who have been camped outside the landmark St. Paul's Cathedral for the past four months lost their court bid to avoid eviction Wednesday in a decision made by London's Court of Appeal.">>>article.cleaned_text[:150](CNN)-OccupyLondonprotesterswhohavebeencampedoutsidethelandmarkSt.Paul's Cathedral for the past four months lost their court bid to avoi>>>article.top_image.srchttp://i2.cdn.turner.com/cnn/dam/assets/111017024308-occupy-london-st-paul-s-cathedral-story-top.jpg

配置

有两种方法可以将配置传递给goose。第一个是 向goose传递一个configuration()对象。第二个是通过 配置指令

例如,如果您想更改goose使用的useragent 通过:

>>>g=Goose({'browser_user_agent':'Mozilla'})

切换解析器:goose现在可以与lxml html解析器或lxml一起使用 汤分析器。默认情况下使用html解析器。如果你想使用 soup解析器在配置dict中传递它:

>>>g=Goose({'browser_user_agent':'Mozilla','parser_class':'soup'})

也可以让goose对网络异常更加宽容。关闭 抛出所有网络异常,将严格配置设置设置为false:

>>>g=Goose({'strict':False})

若要启用图像获取,只需使用“启用图像获取”即可启用它 配置属性:

>>>g=Goose({'enable_image_fetching':True})

goose现在支持语言

例如,用正确的元语言抓取西班牙语内容页 标签:

>>>fromgoose3importGoose>>>url='http://sociedad.elpais.com/sociedad/2012/10/27/actualidad/1351332873_157836.html'>>>g=Goose()>>>article=g.extract(url=url)>>>article.titleu'Las listas de espera se agravan'>>>article.cleaned_text[:150]u'Los recortes pasan factura a los pacientes. De diciembre de 2010 a junio de 2012 las listas de espera para operarse aumentaron un 125%. Hay m\xe1s ciudad'

有些页面没有正确的元语言标记,您可以使用 配置:

>>>fromgoose3importGoose>>>url='http://www.elmundo.es/elmundo/2012/10/28/espana/1351388909.html'>>>g=Goose({'use_meta_language':False,'target_language':'es'})>>>article=g.extract(url=url)>>>article.cleaned_text[:150]u'Importante golpe a la banda terrorista ETA en Francia. La Guardia Civil ha detenido en un hotel de Macon, a 70 kil\xf3metros de Lyon, a Izaskun Lesaka y '

传递{use_meta_language':false,'target_language':'es'}将 强制选择西班牙语。

视频提取

>>>importgoose3>>>url='http://www.liberation.fr/politiques/2013/08/12/journee-de-jeux-pour-ayrault-dans-les-jardins-de-matignon_924350'>>>g=goose3.Goose({'target_language':'fr'})>>>article=g.extract(url=url)>>>article.movies[<goose.videos.videos.Videoobjectat0x25f60d0>]>>>article.movies[0].src'http://sa.kewego.com/embed/vp/?language_code=fr&playerKey=1764a824c13c&configKey=dcc707ec373f&suffix=&sig=9bc77afb496s&autostart=false'>>>article.movies[0].embed_code'<iframe src="http://sa.kewego.com/embed/vp/?language_code=fr&amp;playerKey=1764a824c13c&amp;configKey=dcc707ec373f&amp;suffix=&amp;sig=9bc77afb496s&amp;autostart=false" frameborder="0" scrolling="no" width="476" height="357"/>'>>>article.movies[0].embed_type'iframe'>>>article.movies[0].width'476'>>>article.movies[0].height'357'

中国鹅

有些用户想用goose来制作中文内容。汉语词 分割比西方更难处理 语言。中文需要一个专门的停止词分析器 传递给配置对象。

>>>fromgoose3importGoose>>>fromgoose3.textimportStopWordsChinese>>>url='http://www.bbc.co.uk/zhongwen/simp/chinese_news/2012/12/121210_hongkong_politics.shtml'>>>g=Goose({'stopwords_class':StopWordsChinese})>>>article=g.extract(url=url)>>>printarticle.cleaned_text[:150]香港行政长官梁振英在各方压力下就其大宅的违章建筑(僭建)问题到立法会接受质询,并向香港民众道歉。梁振英在星期二(1210日)的答问大会开始之际在其演说中道歉,但强调他在违章建筑问题上没有隐瞒的意图和动机。一些亲北京阵营议员欢迎梁振英道歉,且认为应能获得香港民众接受,但这些议员也质问梁振英有

阿拉伯语的goose

为了在阿拉伯语中使用goose,你必须使用stopwordsarabic 上课。

>>>fromgoose3importGoose>>>fromgoose3.textimportStopWordsArabic>>>url='http://arabic.cnn.com/2013/middle_east/8/3/syria.clashes/index.html'>>>g=Goose({'stopwords_class':StopWordsArabic})>>>article=g.extract(url=url)>>>printarticle.cleaned_text[:150]دمشق،سوريا(CNN)-أكدتجهاتسوريةمعارضةأنفصائلمسلحةمعارضةلنظامالرئيسبشارالأسدوعلىصلةبـ"الجيش الحر"تمكنتمنالسيطرةعلىمستودعاتللأسل

韩语鹅肉

为了在韩语中使用goose,你必须使用stopwordskorean 上课。

>>>fromgoose3importGoose>>>fromgoose3.textimportStopWordsKorean>>>url='http://news.donga.com/3/all/20131023/58406128/1'>>>g=Goose({'stopwords_class':StopWordsKorean})>>>article=g.extract(url=url)>>>printarticle.cleaned_text[:150]경기도용인에자리잡은민간시험인증전문기업㈜디지털이엠씨(www.digitalemc.com).14년째세계각국의통신·안전·전파규격시험과인증우물만파고있는회사박채규대표가만나기로주인공이다.그는전기전자·무선통신·자동차전장품분야에

待办事项

  • 视频HTML5标签提取

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java OpenGL着色器可在桌面上编译,但不能在Android上编译   java调度器。forward()生成HTTP 500   java从另一个类访问类   java EasyModBus Modbus客户端。ReadHoldingRegisters()返回意外的0   java 安卓bitmap低质量问题   带有signaturePropFile的java Axis2/rampart加密问题   Java,解析xml属性的原始未转换值。Jaxson或jaxb   爪哇太阳报。网inetaddr。ttl属性导致AccessControlException   java简单计算器无法通过println   线程安全java servlet   java从文本文件中获取特定信息   java打包具有字符串数组的哈希映射   java SQL合并以更新值或将值插入到同一个表中   java springrabitmq和线程本地何时是调用clean方法的好时机   windows java在我的64位计算机的任务管理器中显示为32位   java不确定使用什么值来初始化我的神经网络   java Maven插件下载文件