帮朋友写的小工具,后来用不上我就直接帖出来了,信息挺多的 需要的朋友可以拿来用用

<?php
/**
 * 获取抖音作品 用户信息
 * User: 皮皮赖(https://www.52bz.la)
 * Date: 2019/9/14 0014
 * Time: 4:58
 */

//curl
function curl($url, $ref = 'https://www.52bz.la')
{
    $ch = curl_init();
    $ip = rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255) . '.' . rand(0, 255); // 百度蜘蛛
    $timeout = 15;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 0);
    curl_setopt($ch, CURLOPT_REFERER, $ref);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:' . $ip . '', 'CLIENT-IP:' . $ip . ''));
    curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4 (compatible; Baiduspider/2.0; +https://www.52bz.la)");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $content = curl_exec($ch);
    $link = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    curl_close($ch);
    return ['data' => $content, 'url' => $link];
}

//个人中心信息匹配
function woff()
{
    $codes = [
        "&#xe603;" => "0", "&#xe60d;" => "0", "&#xe616;" => "0",
        "&#xe602;" => "1", "&#xe60e;" => "1", "&#xe618;" => "1",
        "&#xe605;" => "2", "&#xe610;" => "2", "&#xe617;" => "2",
        "&#xe604;" => "3", "&#xe611;" => "3", "&#xe61a;" => "3",
        "&#xe606;" => "4", "&#xe60c;" => "4", "&#xe619;" => "4",
        "&#xe607;" => "5", "&#xe60f;" => "5", "&#xe61b;" => "5",
        "&#xe608;" => "6", "&#xe612;" => "6", "&#xe61f;" => "6",
        "&#xe60a;" => "7", "&#xe613;" => "7", "&#xe61c;" => "7",
        "&#xe60b;" => "8", "&#xe614;" => "8", "&#xe61d;" => "8",
        "&#xe609;" => "9", "&#xe615;" => "9", "&#xe61e;" => "9"
    ];
    return $codes;
}

//删除多余html
function noHTML($content)
{
    $content = preg_replace("/<a[^>]*>/i", '', $content);
    $content = preg_replace("/<\/a>/i", '', $content);
    $content = preg_replace("/<div[^>]*>/i", '', $content);
    $content = preg_replace("/<\/div>/i", '', $content);
    $content = preg_replace("/<font[^>]*>/i", '', $content);
    $content = preg_replace("/<\/font>/i", '', $content);
    $content = preg_replace("/<p[^>]*>/i", '', $content);
    $content = preg_replace("/<\/p>/i", '', $content);
    $content = preg_replace("/<i[^>]*>/i", '', $content);
    $content = preg_replace("/<\/i>/i", '', $content);
    $content = preg_replace("/<span[^>]*>/i", '', $content);
    $content = preg_replace("/<\/span>/i", '', $content);
    $content = preg_replace("/<\?xml[^>]*>/i", '', $content);
    $content = preg_replace("/<\/\?xml>/i", '', $content);
    $content = preg_replace("/<o:p[^>]*>/i", '', $content);
    $content = preg_replace("/<\/o:p>/i", '', $content);
    $content = preg_replace("/<u[^>]*>/i", '', $content);
    $content = preg_replace("/<\/u>/i", '', $content);
    $content = preg_replace("/<b[^>]*>/i", '', $content);
    $content = preg_replace("/<\/b>/i", '', $content);
    $content = preg_replace("/<meta[^>]*>/i", '', $content);
    $content = preg_replace("/<\/meta>/i", '', $content);
    $content = preg_replace("/<!--[^>]*-->/i", '', $content);//注释内容
    $content = preg_replace("/<p[^>]*-->/i", '', $content);//注释内容
    $content = preg_replace("/style=.+?['|\"]/i", '', $content);//去除样式
    $content = preg_replace("/class=.+?['|\"]/i", '', $content);//去除样式
    $content = preg_replace("/id=.+?['|\"]/i", '', $content);//去除样式
    $content = preg_replace("/lang=.+?['|\"]/i", '', $content);//去除样式
    $content = preg_replace("/width=.+?['|\"]/i", '', $content);//去除样式
    $content = preg_replace("/height=.+?['|\"]/i", '', $content);//去除样式
    $content = preg_replace("/border=.+?['|\"]/i", '', $content);//去除样式
    $content = preg_replace("/face=.+?['|\"]/i", '', $content);//去除样式
    $content = preg_replace("/face=.+?['|\"]/", '', $content);
    $content = preg_replace("/face=.+?['|\"]/", '', $content);
    $content = str_replace("&nbsp;", "", $content);
    return $content;
}

//获取信息
function user_data($url)
{
    $data = curl($url);
    preg_match('/itemId: "(.*?)"/', $data['data'], $itemId);
    preg_match('/dytk: "(.*?)"/', $data['data'], $dytk);
    preg_match('/uid: "(.*?)"/', $data['data'], $myuid);
    $url_data['itemId'] = $itemId[1];
    $url_data['dytk'] = $dytk[1];
    $json_data = curl('https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' . $url_data['itemId'] . '&dytk=' . $url_data['dytk']);
    $arr_data = json_decode($json_data['data'], 1);
    if ($arr_data['status_code'] != 0) {
        return json_encode(['code' => 404, 'msg' => '出现未知错误!']);
    }
    $info['data']['user']['id'] = $myuid[1];
    $info['data']['works']['url'] = $data['url'];
    $info['data']['works'] = $arr_data['item_list'];
    $user_html = curl('https://www.iesdouyin.com/share/user/' . $info['data']['user']['id']);
    preg_match('/<p class="follow-info">(.*?)<\/p/', $user_html['data'], $user_data);
    preg_match('/<p class="nickname">(.*?)<\/p/', $user_html['data'], $user_name);
    $info['data']['user']['name'] = $user_name[1];
    $user_data_val = noHTML($user_data[1]);
    foreach (woff() as $k => $v) {
        $user_data_val = str_replace($k, $v, $user_data_val);
    }
    $user_data_val = str_replace(' ', '', $user_data_val);
    preg_match('/(.*?)关注/', $user_data_val, $focus);
    preg_match('/关注(.*?)粉丝/', $user_data_val, $fans);
    preg_match('/粉丝(.*?)赞/', $user_data_val, $praise);
    $info['data']['user']['focus'] = $focus[1];
    $info['data']['user']['fans'] = $fans[1];
    $info['data']['user']['praise'] = $praise[1];
    return json_encode($info, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}

echo user_data('http://v.douyin.com/axXGn2/');
最后修改:2019 年 10 月 11 日 05 : 35 PM
如果觉得我的文章对你有用,请随意赞赏