网站的sitemap是爬虫抓取的次要中央,提交了sitemap的url,爬虫会优先抓取。
以是咱们平常要有活期更新sitemap的习气,天生sitemap的办法有不少,第三方对象抓取天生,本人天生。这里我保举本人天生sitemap。由于这样耗费零碎资本起码。
代码以下:
include_once Root_Path . "/vendor/autoload.php"; use Medoo\Medoo; $db = new Medoo([ 'database_type' => 'mysql', 'database_name' => 'menghuiguli', 'server' => 'localhost', 'username' => 'root', 'password' => 'root', ]); $str = "<ul>"; $articles = $db->select('article',"*"); foreach ($articles as $k => $v) { $str .= '<li> <div class="T1"><a href="https://www.80shihua.com/archives/'.$v['id'].'" title="'.$v['name'].'">'.$v['name'].'</a></div> <div class="T2">2019-02-02T10:16:23+08:00</div> <div class="T3">monthly</div> <div class="T4">0.5</div> </li>'; } $str .= '</ul>'; file_put_contents('/sitemap.html', $str);
此中数据库我应用了最玲珑的medooORM模子,十分不便。
咱们只需查出相干文章,而后对应轮回天生sitemap便可。
更多PHP相干常识,请拜访PHP中文网!
以上就是php主动天生sitemap的具体内容,更多请存眷资源魔其它相干文章!
标签: php开发教程 php开发资料 php开发自学 sitmap 爬虫
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!