agentsquidflaps / web-scraper
抓取网站站点地图的HTML元素
1.0.0
2020-09-13 12:17 UTC
Requires
- php: >=7.2
- ext-json: *
- ext-simplexml: *
- symfony/css-selector: ^4.0
- symfony/dom-crawler: ^4.0
Requires (Dev)
- phpunit/phpunit: ^5.0 || ^4.8
This package is auto-updated.
Last update: 2024-09-13 21:20:50 UTC
README
安装
composer install agentsquidflaps/web-scraper
要求
- PHP 7.2 或更高版本
- ext-json
- ext-simplexml
- symfony/dom-crawler 4 或更高版本
- symfony/css-selector 4 或更高版本
文档
请参阅以下基本用法,或者您可以访问https://agentsquidflaps.github.io/web-scraper/#/ 获取更多信息。
用法
基本用法...
(new WebScraper())->setSitemaps([
'https://www.yoursite.com/sitemap.xml'
])->getData()
...这将以JSON格式简单地输出您站点地图中所有页面的HTML。
您还可以针对页面上的特定元素...
(new WebScraper())->setSitemaps([
'https://www.yoursite.com/sitemap.xml'
])
->setElements([
'.btn',
'table'
])
->getData()
...而不是返回整个页面,它将返回符合所提供元素标准页面中的元素。
保存文件
您还可以将数据保存到文件中。为此只需...
(new WebScraper())->setSitemaps([
'https://www.yoursite.com/sitemap.xml'
])
->setFileLocation('somewhere.json')
->saveData()
格式
您还可以以不同的格式输出数据。目前支持格式为JSON、数组和CSV。
(new WebScraper())->setSitemaps([
'https://www.yoursite.com/sitemap.xml'
])
->setFileLocation('somewhere.csv')
->setFormat(WebScraper::FORMAT_CSV)
->saveData()
禁用验证对等方
在抓取URL时不需要验证对等方(尽管强烈推荐)。如果站点地图中提供的URL有可疑或不存在的SSL,这可能会很有用。
(new WebScraper())->setSitemaps([
'http://www.yoursite.com/sitemap.xml'
])
->setFileLocation('somewhere.csv')
->setFormat(WebScraper::FORMAT_CSV)
->setVerifyPeerEnabled(false)
->saveData()