Python,學霸
大家好!今天給你們帶來了透過python requests爬取快手分享連結中提取無浮水印連結的簡單例項, 僅供學習 !
安裝requests:
pip install requests
例項:
import re
import requests
defget_kuaishou(url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 Edg/116.0.1938.76'
}
response = requests.get(url, headers=headers, allow_redirects=True)
content = response.text
pattern = r'"url":"(.*?)"'
url = re.findall(pattern, content)[1]
decodedUniChars = url.encode('utf-8').decode("unicode_escape")
print(decodedUniChars)
if __name__ == '__main__':
url = 'https://www.kuaishou.com/f/X-511NAJFmMwI2a6'
get_kuaishou(url)
輸出:
https://v1.kwaicdn.com/ksc2/lMNP0y-eupBFvNbx0k42gn997CndlyWLsh78H1rgvfUh4IJWxPFC0HmY0tY8H-dsoFEA9gfQaLQXkxWWPj06OZij7J1o2FlZ-D_wdR8FpSyRdCymZcEou7yd64yYlzhh_02W3YpSp9_7fiORGdYngh_V2bLrkcEMALzCFEFiYPl7SMAH_JJuFYYAXRHK69po.mp4?pkey=AAXyRUkor-3Y6sDaTJxQE3OoMei1vW-V-XxAl0k8NRM4U47PGX0QDXCHCoZyHNBVfcUXjiLOX17IbFYeXM1RF8w_iZ-MCDRGh4fr5oh0i2K9Sz9GHIO47TzTIqimKXbk6Wg&tag=1-1711175835-unknown-0-zhgjmff8ea-c1cf0c8825c19886&clientCacheKey=3x94awku7fajdss_b.mp4&di=246b6107&bp=10004&tt=b&ss=vp