public function init_tieba() { $url = "http://tieba.baidu.com/f/like/mylike?&pn=1"; $html = $this->request("get", $url); $html = mb_convert_encoding($html, "UTF-8", "gbk,gb2312,UTF-8"); echo "--geting html---\n"; preg_match('/\\<a href="\\/f\\/like\\/mylike\\?\\&pn=(.*?)"\\>尾页\\<\\/a\\>/', $html, $total); $total = $total[1]; $names = []; echo "--geting title---\n"; for ($i = 1; $i <= $total; $i++) { $url = "http://tieba.baidu.com/f/like/mylike?&pn=" . $i; $names = array_merge($names, $this->fetch_tieba($url)); } echo "--insert database---\n"; foreach ($names as $k => $v) { if (!tieba::where(['name' => $v])->get()->first()) { \tieba::create(['name' => $v]); } } echo "-- down insert ---\n"; exit(__FILE__ . __LINE__); }