iansltx / pnwphp-2017-schedule-client
PNWPHP 2017 会议日程的优雅爬虫
dev-master / 1.0.x-dev
2017-09-06 03:43 UTC
Requires
- php: >=7.1
- fabpot/goutte: ^3.2
This package is auto-updated.
Last update: 2024-09-06 18:42:28 UTC
README
爬取PNWPHP 2017日程,提供会议活动列表。
此文件是语法正确的PHP文件,因此您可以运行它以查看示例如何工作。没错,这就是为什么到处都有闭合标签的原因。
要开始,请运行 composer require iansltx/pnwphp-2017-schedule-client
。然后
<?php require __DIR__ . '/vendor/autoload.php'; $client = \iansltx\PNWPHP2017ScheduleClient\Client::create(); // set up a client with default params print("Getting schedule...\n"); $schedule = $client->getSchedule(); // make the call to the PNWPHP website and scrape the schedule ?>
日程是一个包含Event对象的事件集合,这些对象实现了__toString()和jsonSerialize()方法。两者都返回适合显示的字符串,因此如果您想在JSON blob中获取更多数据,则需要手动从每个事件中提取数据。
<?php date_default_timezone_set('America/Los_Angeles'); /** @var \iansltx\PNWPHP2017ScheduleClient\Schedule $schedule */ print("The next event is " . $schedule->filterOutPast(new \DateTimeImmutable('2017-09-10'))->first() . ".\n"); ?>