定制 simplon/spider 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

simplon/spider

最新稳定版本:0.1.13

Composer 安装命令:

composer require simplon/spider

包简介

Retrieve a website's essential information

README 文档

README

								     /      \
							  	  \  \  ,,  /  /
								   '-.`\()/`.-'
								  .--_'(  )'_--.
							     / /` /`""`\ `\ \
			 					  |  |  ><  |  |
								  \  \      /  /
 									  '.__.'
			
								  Simplon/Spider

Build Status

Intro

What is simplon/spider?

Spider parses a given html document and aggregates all essential data:

  • title
  • description
  • keywords
  • all h1 contents
  • open-graph tags
  • twitter tags
  • all images

It basically gives you sort of the same response as Facebook's scraper. However, Facebook's scraper does not give you all essential data.

Facebook scraper response:

{
   "og_object":{
      "id":"379786107965",
      "description":"Find the latest breaking news and information on the top stories, weather, business, entertainment, politics, and more. For in-depth coverage, CNN provides special reports, video, audio, photo galleries, and interactive guides",
      "title":"Breaking News, U.S., World, Weather, Entertainment & Video News - CNN.com",
      "type":"website",
      "updated_time":"2015-09-01T13:15:53+0000",
      "url":"http:\/\/www.cnn.com\/"
   },
   "share":{
      "comment_count":0,
      "share_count":1340555
   },
   "id":"http:\/\/cnn.com"
}

Spider response:

{
   "title":"Breaking News, U.S., World, Weather, Entertainment & Video News - CNN.com",
   "description":"Find the latest breaking news and information on the top stories, weather, business, entertainment, politics, and more. For in-depth coverage, CNN provides special reports, video, audio, photo galleries, and interactive guides",
   "keywords":"breaking news, news online, U.S. news, world news, developing story, news video, CNN news, weather, business, money, politics, law, technology, entertainment, education, travel, health, special reports, autos, CNN TV",
   "url": "http:\/\/www.cnn.com\/",
   "images":[
      "http://i2.cdn.turner.com/cnnnext/dam/assets/150901143136-budapest-migrant-protest-fists-large-169.jpg",
      "http://i2.cdn.turner.com/cnnnext/dam/assets/110902115913-gates-of-auschwitz-large-169.jpg"
   ],
   "openGraph":{
      "pubdate":"2014-02-24T14:45:54Z",
      "url":"http://www.cnn.com",
      "title":"Breaking News, U.S., World, Weather, Entertainment &amp; Video News - CNN.com",
      "description":"Find the latest breaking news and information on the top stories, weather, business, entertainment, politics, and more. For in-depth coverage, CNN provides special reports, video, audio, photo galleries, and interactive guides",
      "site_name":"CNN",
      "type":"website"
   },
   "twitter":{
      "card":"summary_large_image"
   }
}

Any dependencies?

  • PHP 5.4
  • CURL

Install

Easy install via composer. Still no idea what composer is? Inform yourself here.

{
    "require": {
        "simplon/spider": "*"
    }
}

Examples

The following examples are straight forward and should not require any additional explaintation.

Parse by fetching the page first

use Simplon\Spider\Spider;

// fetch and parse
$data = Spider::fetchParse('http://cnn.com');

echo json_encode($data); // json encode result

Parse by existing html

use Simplon\Spider\Spider;

// page html
$html = '...';

// fetch and parse
$data = Spider::parse($html, 'http://cnn.com'); // URL is needed to rebuild absolute image paths

echo json_encode($data); // json encode result

Result in both cases

{
   "title":"Breaking News, U.S., World, Weather, Entertainment & Video News - CNN.com",
   "description":"Find the latest breaking news and information on the top stories, weather, business, entertainment, politics, and more. For in-depth coverage, CNN provides special reports, video, audio, photo galleries, and interactive guides",
   "keywords":"breaking news, news online, U.S. news, world news, developing story, news video, CNN news, weather, business, money, politics, law, technology, entertainment, education, travel, health, special reports, autos, CNN TV",
   "url": "http:\/\/www.cnn.com\/",
   "images":[
      "http://i2.cdn.turner.com/cnnnext/dam/assets/150901143136-budapest-migrant-protest-fists-large-169.jpg",
      "http://i2.cdn.turner.com/cnnnext/dam/assets/110902115913-gates-of-auschwitz-large-169.jpg"
   ],
   "openGraph":{
      "pubdate":"2014-02-24T14:45:54Z",
      "url":"http://www.cnn.com",
      "title":"Breaking News, U.S., World, Weather, Entertainment &amp; Video News - CNN.com",
      "description":"Find the latest breaking news and information on the top stories, weather, business, entertainment, politics, and more. For in-depth coverage, CNN provides special reports, video, audio, photo galleries, and interactive guides",
      "site_name":"CNN",
      "type":"website"
   },
   "twitter":{
      "card":"summary_large_image"
   }
}

License

simplon/spider is freely distributable under the terms of the MIT license.

Copyright (c) 2015 Tino Ehrich (tino@bigpun.me)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

统计信息

  • 总下载量: 407
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-01