闲鱼的商品详情接口【x-sign】【sign】【_m_h5_tk】【_m_h5_tk_enc】

闲鱼商品详情接口实现,主要是爬取网页端商品详情数据url地址:
https://h5api.m.taobao.com/h5/mtop.taobao.idle.awesome.detail/1.0/?jsv=2.4.5&appKey=12574478&t=1592477911574&sign=b2aa128cf2a03abf69d7708473bac731&api=mtop.taobao.idle.awesome.detail&v=1.0&AntiCreep=true&AntiFlood=true&preventFallback=true&type=jsonp&dataType=jsonp&callback=mtopjsonp2&data=%7B%22itemId%22%3A%22620691241377%22%7D

最终实现效果:

最终数据如下:

{“api”:“mtop.taobao.idle.awesome.detail”,“data”:{“needDecryptKeys”:[“sellerDO.nick”,“sellerDO.uniqueName”],“itemDO”:{“priceUnit”:"",“imageInfos”:[{“major”:“true”,“videoId”:“0”,“widthSize”:“1080”,“heightSize”:“896”,“type”:“0”,“url”:“http://img.alicdn.com/bao/uploaded/i3/O1CN01waLaoh1nb3Il5LqNl_!!0-fleamarket.jpg”,“labels”:[{“orientation”:“2”,“top”:“0.3313343328335832”,“left”:“0.6844444173177083”,“actionUrl”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”,“text”:“徽缘.伟”}]},{“major”:“false”,“videoId”:“0”,“widthSize”:“1080”,“heightSize”:“804”,“type”:“0”,“url”:“http://img.alicdn.com/bao/uploaded/i3/O1CN01dv49lC1gfuBgmpO72_!!0-fleamarket.jpg”,“labels”:[{“orientation”:“2”,“top”:“0.32733632420850123”,“left”:“0.6337777506510417”,“actionUrl”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”,“text”:“徽缘.伟”}]},{“major”:“false”,“videoId”:“0”,“widthSize”:“1080”,“heightSize”:“860”,“type”:“0”,“url”:“http://img.alicdn.com/bao/uploaded/i4/O1CN01xkk9AV1ofv7whllsa_!!0-fleamarket.jpg”,“labels”:[{“orientation”:“2”,“top”:“0.32083958020989506”,“left”:“0.6053333333333333”,“actionUrl”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”,“text”:“徽缘.伟”}]},{“major”:“false”,“videoId”:“0”,“widthSize”:“1080”,“heightSize”:“816”,“type”:“0”,“url”:“http://img.alicdn.com/bao/uploaded/i4/O1CN01hu1p3M1EIGVDQOe1U_!!0-fleamarket.jpg”,“labels”:[{“orientation”:“2”,“top”:“0.32133932270925086”,“left”:“0.6186666666666667”,“actionUrl”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”,“text”:“徽缘.伟”}]},{“major”:“false”,“videoId”:“0”,“widthSize”:“1080”,“heightSize”:“844”,“type”:“0”,“url”:“http://img.alicdn.com/bao/uploaded/i3/O1CN01Vxk5t01bKlpizYn2N_!!0-fleamarket.jpg”,“labels”:[{“orientation”:“2”,“top”:“0.31784107946026985”,“left”:“0.6622222086588542”,“actionUrl”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”,“text”:“徽缘.伟”}]},{“major”:“false”,“videoId”:“0”,“widthSize”:“1080”,“heightSize”:“820”,“type”:“0”,“url”:“http://img.alicdn.com/bao/uploaded/i1/O1CN01JIV4J61iv8ajkS51X_!!0-fleamarket.jpg”,“labels”:[{“orientation”:“2”,“top”:“0.31334332833583206”,“left”:“0.6364444173177083”,“actionUrl”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”,“text”:“徽缘.伟”}]}],“itemType”:“detailCommonBuy”,“quantity”:“1”,“simpleItem”:“true”,“originalPrice”:“0”,“transportFee”:“0.00”,“itemStatusStr”:“在线”,“favorCnt”:“4”,“templateId”:“0”,“title”:“玉化手串8.2,22.8克!”,“labels”:[{“display”:"#徽缘.伟",“url”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”},{“display”:"#徽缘.伟",“url”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”},{“display”:"#徽缘.伟",“url”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”},{“display”:"#徽缘.伟",“url”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”},{“display”:"#徽缘.伟",“url”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”},{“display”:"#徽缘.伟",“url”:“https://market.m.taobao.com/app/idleFish-F2e/app-channels/search_set?wh_weex=true&tagCode=0&tagName=%E5%BE%BD%E7%BC%98.%E4%BC%9F&reqFrom=DETAIL_ITEMTAG&bizType=customTag&condition=%7B%22itemId%22%3A%22615441296179%22%7D”}],“itemId”:“615441296179”,“trackParams”:{“itemId”:“615441296179”,“sellerId”:“1104528449”,“sellerBucketId”:“10”},“wantCnt”:“37”,“itemStatus”:“0”,“soldPrice”:“1200”,“secuGuide”:{“secuTitle”:“什么是闲鱼支付宝担保交易?”,“secuIcon”:“https://gw.alicdn.com/tps/TB1xwS9MVXXXXbGXVXXXXXXXXXX-24-24.png”,“secuContent”:“担保交易”,“secuBtmContext”:“点击查看更多知识”,“secuBtm”:“闲置商品不支持7天无理由退货服务。请保证在闲鱼平台进行支付,否则闲鱼将无法保证您交易的安全。",“secuBtmUrl”:“https://h5.m.taobao.com/alicare/index.html?from=mmcHJdQwpZ”,“secuBody”:“https://gw.alicdn.com/mt/TB1V4Q9OVXXXXa7aXXXXXXXXXXX-488-430.png”},“categoryId”:“50023914”,“browseCnt”:“2954”,“desc”:“玉化手串8.2,22.8克!\n感兴趣的话点“我想要”和我私聊吧~”},“sellerDO”:{“city”:“保定”,“portraitUrl”:“http://img.alicdn.com/bao/uploaded/i3/O1CN01ULbAqk1ylY68jPlrO_!!0-fleamarket.jpg”,“zhimaAuth”:“true”,“publishCity”:“发布于保定”,“nick”:"z**b”,“zhimaLevelInfo”:{“levelCode”:“A”,“levelName”:“信用极好”},“sellerId”:“1104528449”,“uniqueName”:“徽***伟”,“xianyuSummary”:“来闲鱼410天了,卖出过5件宝贝。90后巨蟹座女生。喜欢运动、音乐、娱乐。”,“cityUrl”:“https://fleamarket.taobao.com/wow/z/act/default/localCity?wh_biz=tm&wh_weex=true”,“lastVisitTime”:“刚刚擦亮”,“identityTags”:[{“iconHeight”:“32”,“trackParams”:{“appearTrackName”:"",“trackCtrlName”:“Button-Shiren”},“iconWidth”:“32”,“link”:“https://h5.m.taobao.com/2shou/pd/realVerifyUrl.html?userId=1104528449&isVerify=1”,“iconUrl”:“https://gw.alicdn.com/bao/uploaded/TB1E3aKPFXXXXcKXpXXXXXXXXXX-32-32.png”,“text”:“实人认证已通过”,“type”:“1”},{“iconHeight”:“32”,“trackParams”:{“appearTrackName”:"",“trackCtrlName”:“Button-Zhima”},“iconWidth”:“32”,“link”:“fleamarket://personalPage?userid=1104528449&ignore=false&userzhima=true&loginuserzhima=false”,“iconUrl”:“https://gw.alicdn.com/tfs/TB1DuVuB7P2gK0jSZPxXXacQpXa-32-32.png”,“text”:“芝麻信用已授权”,“type”:“100”}],“levelTags”:[{“iconHeight”:“28.0”,“iconWidth”:“129.0”,“iconUrl”:“https://gw.alicdn.com/tfs/TB1alBPybj1gK0jSZFOXXc7GpXa-168-36.png”},{“iconHeight”:“28.0”,“iconWidth”:“28.0”,“iconUrl”:“https://gw.alicdn.com/tfs/TB1DM04aGWs3KVjSZFxXXaWUXXa-28-28.png”}]},“trackParams”:{“itemId”:“615441296179”,“sellerOptions”:“simplePub|newTagPage|myPubSameSpu|toBuyB|spuGuide|itemGuide|myTabAlert|tagV2|glbV2|textSameSpu|mtbFeeds|mtbSell|mtbHome”,“sellerId”:“1104528449”,“detailRedirectPublishUrl”:“https://market.m.taobao.com/app/idleFish-F2e/purchaseMatch/pages/new-custom-demand?wh_weex=true&needLogin=1&need_login=true&scene=toBuyPubDetailPush&sourceId=bid_detail_button&spuId=-1&itemId=615441296179&tbNid=0&transparent=true&hideNavBar=true&is_modal=true&modalPStyle=true”,“mainPic”:“http://img.alicdn.com/bao/uploaded/i3/O1CN01waLaoh1nb3Il5LqNl_!!0-fleamarket.jpg”,“sellerBucketId”:“10”,“sellerInBuyBucketId”:“11”,“sellerInBuyOptions”:“newTagPage|pop”,“categoryId”:“50023914”},“serverTime”:“2020-06-18 21:46:14”},“ret”:[“SUCCESS::调用成功”],“v”:“1.0”}
语言实现:

php + nodejs

nodejs实现sign算法(核心)
php实现爬虫 (可以改写为任何的语言形式)
目前 基本上实现了毫秒级别能爬1条数据
需要的请联系我 QQ: 84075041, 此技术仅供参考!

代码截图:

handler = new Redis(); //从配置读取 $this->handler->connect($data['hostname'], $data['port']); $this->handler->auth($data['auth']); $this->handler->select($dbindex); } public static function getInstance($dbindex = 0) { if (!isset(self::$_instance[$dbindex]) or FALSE == (self::$_instance[$dbindex] instanceof self)) { self::$_instance[$dbindex] = new self($dbindex); } return self::$_instance[$dbindex]; } /**key value get**/ public function GET($key) { return $this->handler->get($key); } /**key value set 过期时间为 $exp**/ public function SET($key, $value, $exp) { $this->handler->setex($key, $exp, $value); } public function __destruct() { if ($this->handler) { $this->handler->close(); } } } /** * Created by PhpStorm. * User: Administrator * Date: 2017/9/28 0028 * Time: 18:20 */ class Network { public static function RequestData($url, $data = null) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; } } function getItemInfo($itemid){ global $config ; $tkCookie = getTkCookie(); $commend = $config['node_bin'] . " " .$config['project_path'] . "/cookie.js {$itemid} {$tkCookie['_m_h5_tk']} {$tkCookie['_m_h5_tk_all']} {$tkCookie['_m_h5_tk_enc']}"; $url = trim(my_exec($commend)); //echo "url is : " . $url . "\n"; //echo "Cookie:_m_h5_tk={$tkCookie['_m_h5_tk_all']};_m_h5_tk_enc={$tkCookie['_m_h5_tk_enc']} ". "\n"; $ipData = getProxyIp(); if( empty($ipData['ip']) ){ echo date("Y-m-d H:i:s" , time()) . ">>>>>>没有获取到代理的IP \n"; return []; } //print_r($ipData); $headers = array( "User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0", "Cookie:_m_h5_tk={$tkCookie['_m_h5_tk_all']};_m_h5_tk_enc={$tkCookie['_m_h5_tk_enc']}", "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Cache-Control:max-age=0", "Referer:https://market.m.taobao.com/app/idleFish-F2e/widle-taobao-rax/page-detail?wh_weex=true&wx_navbar_transparent=true&id=620691241377&ut_sk=1.Xorif98ZyO4DAFOaBXKdI6l2_21407387_1592450094432.Copy.detail.620691241377.1094213846&forceFlush=1", ); //print_r($headers); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url , CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 100, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => $headers, CURLOPT_SSL_VERIFYHOST => false , CURLOPT_SSL_VERIFYPEER => false , //CURLOPT_PROXY => $ipData['ip'], CURLOPT_PROXYPORT => $ipData['port'], CURLOPT_USERPWD => "{$config['proxy']['AuthKey']}:{$config['proxy']['AuthPwd']}", CURLOPT_PROXYTYPE => CURLPROXY_HTTP, CURLOPT_HTTPAUTH => CURLAUTH_BASIC )); $resp_str = curl_exec($curl); $err = curl_error($curl); curl_close($curl); //echo "resp:" . $resp_str; $result = json_decode( $resp_str , true ); $title = isset( $result['data']['itemDO']['title']) ?$result['data']['itemDO']['title'] :"" ; $itemStatus = isset( $result['data']['itemDO']['itemStatus']) ?$result['data']['itemDO']['itemStatus'] :"" ; $itemStatusStr = isset( $result['data']['itemDO']['itemStatusStr']) ?$result['data']['itemDO']['itemStatusStr'] :"" ; $soldPrice = isset( $result['data']['itemDO']['soldPrice']) ?$result['data']['itemDO']['soldPrice'] :"" ; $nick = isset( $result['data']['sellerDO']['nick']) ?$result['data']['sellerDO']['nick'] :"" ; if( empty($title) ){ //delProxyIpCache(); } //print_r($result); //成功率统计下 if( empty($title) ){ $handler = RedisDB::getInstance(12)->handler; $handler->incr("s_".date("YmdH")); //$handler->incr("s_".date("YmdHi")); } $res = [ 'title' => $title , 'itemStatus' => $itemStatus, 'itemStatusStr' => $itemStatusStr, 'nick' => $nick, 'resp' => $resp_str, 'soldPrice' => $soldPrice ] ; if( empty($title ) ){ echo date("Y-m-d H:i:s" , time()) . ">>>>没有爬到数据返回:" .$resp_str . "\n" ; }else{ echo date("Y-m-d H:i:s" , time()) . " >>>>标题:" .$title. " , 价格:{$soldPrice} , 状态:{$itemStatusStr} \n" ; echo "
"; echo "

原始信息如下:

"; echo $resp_str ; } return $res ; } function getTkCookie(){ $RedisDB = RedisDB::getInstance(12); $cookieStr = $RedisDB->GET( "cookieStr" ); if( $cookieStr ){ return json_decode($cookieStr , true ); } global $config ; $commend = $config['token_commond'] ; $res = my_exec($commend); $res = json_decode( $res , true ); $_m_h5_tk = isset($res['_m_h5_tk']) ? $res['_m_h5_tk'] :""; $_m_h5_tk_enc = isset($res['_m_h5_tk_enc']) ? $res['_m_h5_tk_enc'] :""; $_m_h5_tk_all = $_m_h5_tk; $data = @explode("_",$_m_h5_tk); $_m_h5_tk = $data[0]; $res['_m_h5_tk'] = $_m_h5_tk; $res['_m_h5_tk_all'] = $_m_h5_tk_all; $res['_m_h5_tk_enc'] = $_m_h5_tk_enc; if( $_m_h5_tk ){ $RedisDB->SET( "cookieStr" , json_encode($res) , 3000 ); } return $res ; } function my_exec($cmd, $input='') {$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes); fwrite($pipes[0], $input);fclose($pipes[0]); $stdout=stream_get_contents($pipes[1]);fclose($pipes[1]); $stderr=stream_get_contents($pipes[2]);fclose($pipes[2]); $rtn=proc_close($proc); return $stdout; } function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } /** * 删除代理IP缓存 */ function delProxyIpCache(){ $handler = RedisDB::getInstance(12)->handler; $handler->del("proxy_ip"); } /** * 获取代理的IP */ function getProxyIp(){ /*return [ 'ip' =>'117.24.81.15', 'port' => '11542' ];*/ $RedisDB = RedisDB::getInstance(12); $proxy_ip = $RedisDB->GET( "proxy_ip" ); if( $proxy_ip ){ return json_decode($proxy_ip , true ); } releaseIp(); allocateIp(); global $config ; $url = "https://proxy.qg.net/query?Key=" . $config['proxy']['key']; $resp = Network::RequestData( $url ); $resp = json_decode( $resp , true ); $ip = isset($resp['TaskList'][0]['Data']['0']['IP'])?$resp['TaskList'][0]['Data']['0']['IP']:""; $port = isset($resp['TaskList'][0]['Data']['0']['port'])?$resp['TaskList'][0]['Data']['0']['port']:""; $data = [ 'ip' => $ip , 'port' => $port ]; if( $ip ){ $proxy_ip = $RedisDB->SET( "proxy_ip" , json_encode($data) , 10 ); } return $data; } /** * 申请代理IP */ function allocateIp(){ global $config ; $url = "https://proxy.qg.net/allocate?Key={$config['proxy']['key']}&Num=1&KeepAlive=60"; $resp = Network::RequestData( $url ); return $resp ; } /** * 释放代理IP */ function releaseIp(){ global $config ; $url = "https://proxy.qg.net/release?Key={$config['proxy']['key']}&IP=*"; $resp = Network::RequestData( $url ); return $resp ; } $url = isset($_POST['url']) ? trim($_POST['url']) :""; if( empty($url)){ echo "url is error "; exit; } $url = isset($_POST['url']) ? trim($_POST['url']) :""; if( empty($url ) ){ exit("error"); } $config = [ 'proxy' => ['key' => '' , 'AuthKey' => '' , 'AuthPwd' => '' ] , 'redis' => [ 'hostname' => '127.0.0.1', 'port' => '6379', 'auth' => '', ] , 'token_commond' => "/usr/local/phantomjs-2.1.1-linux-x86_64/bin/phantomjs scrapy.js 5000 '{$url}'" , //生成token的命令 'phantomjs_path' => "",//phantomjs_path 'project_path' => "",//项目文件夹 'node_bin' => "",//node的执行文件路径 ] ; $res = parse_url( $url ); $query = $res['query']; parse_str( $query , $queryData); $itemid = $queryData['id']; if( empty($itemid ) ){ exit("error........itemid "); } getItemInfo($itemid); ?>

接口文档地址:

https://www.showdoc.cc/985778661176731?page_id=5110060088025794

在线解码地址 : 在线base64解码

# 下面是进行base64编码的 解码就可以看到我了!!


# cXE6IDg0MDc1MDQx



你可能感兴趣的:(闲鱼的商品详情接口【x-sign】【sign】【_m_h5_tk】【_m_h5_tk_enc】)