>本教程演示了使用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中文網其他相關文章!