Python抖音昵称/号转为抖音uid

  1. import random
  2.  
  3. import requests
  4.  
  5. SEARCH_API = "http://aweme.snssdk.com//aweme/v1/discover/search/?device_id={}&aid=1128&cursor=0&" \
  6. "search_source=discover&query_correct_type=1&count=1&keyword={}&hot_search=0&type=1"
  7. HEADERS = {
  8. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) '
  9. 'Chrome/78.0.3904.108 Safari/537.36'}
  10.  
  11.  
  12. def generate_nonce():
  13. nonce = ''
  14. for i in range(8):
  15. nonce += str(random.randint(0, 9))
  16. return nonce
  17.  
  18.  
  19. nonce = generate_nonce()
  20.  
  21.  
  22. def douyin_name_to_uid(user_name):
  23. data = requests.get(SEARCH_API.format(nonce, user_name), headers=HEADERS).json()
  24. try:
  25. user_uid = data['user_list'][0]['user_info']['uid']
  26. return user_uid
  27. except IndexError:
  28. pass
  29. return None
  30.  
  31.  
  32. if __name__ == '__main__':
  33. douyin_name = input('请输入抖音号:')
  34. douyin_uid = douyin_name_to_uid(douyin_name)
  35. if douyin_uid:
  36. print(f'用户[{douyin_name}]的UID为:{douyin_uid}')
  37. else:
  38. print('查找失败!')

https://github.com/kushao1267/douyin_uid_converter

输入抖音号或者抖音昵称,返回抖音uid

其实功能不单单那么简单,这接口可以搜索昵称,搜索关键字返回用户列表

发表评论

邮箱地址不会被公开。 必填项已用*标注