现在,我使用GuzzleHttp从tiktok网站上实现了laravel项目以搜寻值。
例如。我想从该网址
抓取数据 https://www.tiktok.com/@zihaolol98
,我想收集姓名,个人资料图片,关注者数量。
从现在开始,我只是成功地任命了这个名字。这是我的代码。
$client = new \GuzzleHttp\Client();
//Get Name
$response = $client->get('https://www.tiktok.com/@zihaolol98', ['headers' => ['User-Agent' => 'spider']]);
preg_match_all('/<header(.*?)class="(.*?)">(.*?)<\/header>/s', $response->getBody(), $getname);
preg_match_all('/<h1(.*?)class="(.*?)">(.*?)<\/h1>/s', $getname[3][0], $name_found);
$name = $name_found[3][0];
它返回zihaolol98
作为名称
接下来,我想收集个人资料图片和关注者数量。我已经尝试过此代码,但仍然失败。这是代码
//crawl Profile Picture
preg_match_all('/jsx-\d{10}(.*?)jsx-\d{10}(.*?)(.*?)jsx-\d{10}(.*?)avatar-wrapper(.*?)/s', $response->getBody(), $picture_matches);
dump($picture_matches);
//crawl followers
preg_match_all('/title="Followers"/s', $response->getBody(), $follower);
dump($follower);
如果在浏览器上看到检查元素,我希望代码返回值
个人资料图片https://mpak-suse1.akamaized.net/res/usericon/304/icon-56105311844962304-425.jpg
关注者330.6K
请帮帮我。有可能返回我想要的值吗?