731my / php-meta-tags
一个用于从HTML内容中获取元标签的PHP库
dev-master
2018-06-29 08:24 UTC
Requires
- php: >=7.0.0
This package is not auto-updated.
Last update: 2024-09-22 16:36:09 UTC
README
用于从HTML内容中提取元标签的PHP库
需求
- php >= 7.0.0
- CURL
安装
composer require 731my/php-meta-tags
用法
简单使用
$Reader = new Reader('https://www.bbc.com/news/uk-england-44520759'); $Meta = new MetaFetcher($Reader); print_r($Meta->meta());
过滤特定标签
$Reader = new Reader('https://www.bbc.com/news/uk-england-44520759'); $Meta = new MetaFetcher($Reader); print_r($Meta->meta(['og:image']));
从文件加载
$Reader = new Reader('/tmp/file.html', Type::FILE); $Meta = new MetaFetcher($Reader);
从数据加载
$Reader = new Reader("<html>....</html>", Type::DATA); $Meta = new MetaFetcher($Reader);
配置
你可以自定义user-agent、timeout、referer
$Config = new Config(); $Config->setTimeout(20); // in seconds , default: 10 $Config->setUserAgent('731MY'); // default: Googlebot/2.1 (+http://www.google.com/bot.html) $Config->setReferer('https://google.com/'); // default: null $Meta = new MetaFetcher(new Reader('https://www.bbc.com/news/uk-england-44520759',Type::URL,$Config));
许可证
MIT License
Copyright (c) 2016 Helmy Al Dobhany
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.