当你在小红书复制某篇笔记链接,黏贴出来是这个样子的
这种链接只有打开小红书app才能够访问,那么怎么把这种链接转换为可直接访问的格式呢?
执行下方代码即可
import requests
import jsondef shortToLong(shortUrl):url = 'http://api.dwzjh.com/api/reduction?url={}'.format(shortUrl)res = requests.get(url).textres_dict = json.loads(res)longUrl = res_dict['longurl'] # 获取app长链接print(longUrl)noteUrl = longUrl.split('?')[0]print(noteUrl)if __name__ == '__main__':shortToLong('http://xhslink.com/do9xGe')
执行得到
https://www.xiaohongshu.com/discovery/item/6183d181000000000102e173?xhsshare=CopyLink&appuid=58494c1e5e87e726bb6d068e&apptime=1636474357
https://www.xiaohongshu.com/discovery/item/6183d181000000000102e173Process finished with exit code 0