>本教程演示了使用Diffbot的结构化数据提取构建站点搜索引擎超过WordPress功能。 我们将利用Diffbot的API进行爬行和搜索,并采用宅基地改进的开发环境。
键优点:
我们将分两个步骤创建一个Sitepoint搜索引擎:
crawljob到index sitepoint.com,自动更新新内容。
a(在后续文章中)通过搜索API查询索引数据。蜘蛛URL。
> 创建:
composer require swader/diffbot-php-client
运行job.php
include 'vendor/autoload.php'; use Swader\Diffbot\Diffbot; $diffbot = new Diffbot('my_token'); // Replace 'my_token' with your Diffbot token $job = $diffbot->crawl('sp_search'); $job ->setSeeds(['https://www.sitepoint.com']) ->notify('your_email@example.com') // Replace with your email ->setMaxToCrawl(1000000) ->setMaxToProcess(1000000) ->setRepeat(1) ->setMaxRounds(0) ->setPageProcessPatterns(['']) ->setOnlyProcessIfNew(1) ->setUrlCrawlPatterns(['^http://www.sitepoint.com', '^https://www.sitepoint.com']) ->setApi($diffbot->createArticleAPI('crawl')->setMeta(true)->setDiscussion(false)); $job->call();
使用搜索API查询索引数据:php job.php
访问。 使用。
$search = $diffbot->search('author:"Bruno Skvorc"'); $search->setCol('sp_search'); $result = $search->call(); // Display results (example) echo '<table><thead><tr><td>Title</td><td>Url</td></tr></thead><tbody>'; foreach ($search as $article) { echo '<tr><td>' . $article->getTitle() . '</td><td><a href="' . $article->getResolvedPageUrl() . '">Link</a></td></tr>'; } echo '</tbody></table>';
difbot为创建自定义搜索引擎提供了强大的解决方案。虽然对个人来说可能是昂贵的,但它为管理大型网站的团队和组织提供了巨大的好处。 请记住在爬行之前尊重网站服务条款。 下一部分将着重于构建搜索引擎的GUI。
>经常询问的问题(改写和合并):
以上是用difbot爬行和搜索整个域的详细内容。更多信息请关注PHP中文网其他相关文章!