python抖X解析源码
本帖最后由 wushaominkk 于 2019-6-25 17:41 编辑废话不多说,直接贴代码,粘上就能用!
博客粘过来的,无奈浏览器自动翻译了,没审核,贼尴尬。。。。已经更新:
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'宋体';font-size:15.0pt;">import requests
import json
import logging
import re
from urllib import parse
def analysis_douying(share_url):
try:
response = requests.get(share_url, allow_redirects=False)
aweme_id = re.findall('(\d+)', parse.urlparse(response.headers.get('Location')).path)
except Exception as e:
logging.warning('错误的地址 {}'.format(e))
return json.dumps({'status': 0, 'info': '错误的地址'})
url = 'https://aweme.snssdk.com/aweme/v1/aweme/detail/'
params = {
"aweme_id": aweme_id,
"origin_type": "web",
"retry_type": "no_retry",
"iid": "75186358813",
"device_id": "68273753722",
"ac": "wifi",
"channel": "tengxun_new",
"aid": "1128",
"app_name": "aweme",
"version_code": "660",
"version_name": "6.6.0",
"device_platform": "android",
"ssmix": "a",
"device_type": "OPPO R11",
"device_brand": "OPPO ",
"language": "zh",
"os_api": "22",
"os_version": "5.1.1",
"uuid": "866174010180467",
"openudid": "b42e992398373803",
"manifest_version_code": "660",
"resolution": "720*1280",
"dpi": "240",
"update_version_code": "6602",
"_rticket": "1560432451284",
"mcc_mnc": "46007",
"js_sdk_version": "1.16.2.7",
"ts": "1560432451"
}
headers = {
'User-Agent': 'com.ss.android.ugc.aweme/660 (Linux; U; Android 5.1.1; zh_CN; OPPO R11; Build/NMF26X; Cronet/58.0.2991.0)'
}
response = requests.get(url=url, params=params, headers=headers)
json_info = json.loads(response.text)
try:
title = json_info['aweme_detail']['desc']
rel_video_url = json_info['aweme_detail']['video']['play_addr']['url_list']
return json.dumps({'status': 1, 'title': title, 'rel_video_url': rel_video_url})
except Exception as e:
logging.warning('解析失败: {}'.format(e))
return json.dumps({'status': 0, 'info': '解析失败'})
if __name__ == '__main__':
print(json.loads(analysis_douying('http://v.douyin.com/rqW8M5/')))
</pre> 愤怒的小车 发表于 2019-6-25 16:12
兄弟,哪里抄的?代码明显发一过来的啊
博客粘过来的,无奈浏览器自动翻译了,没审核。已经更新 obeina 发表于 2019-6-25 17:17
博客粘过来的,无奈浏览器自动翻译了,没审核。已经更新
好的,多谢更新 兄弟,哪里抄的?代码明显发一过来的啊 {:1_896:}像是翻译的...try翻译成尝试..关键是中文... 这代码。。你不尴尬吗 代码抄得都解析成中文了.不知道楼主有没有看懂 代码抄得都翻译了。。。 你贴代码时是不是开启了浏览器翻译?
这代码怎么成中文了?
肉眼都过不了,机器上肯定跑不了。 这代码好尴尬呀 难怪我就说是中文的,还想着是注释,看清楚没有注释符号。就是翻译了
页:
[1]
2