The XG video appearance area is so amazing, I only use 30 lines of Python code to download in batches, save it locally and watch it slowly

I don’t know where all the talented people (lsp) usually watch videos. Some people say a certain fish dance area, and some say a certain tooth dance area. If you ask me, it’s not as good as watermelon shipin. Everyone here is talented, and they talk Sounds good, I really like it here...



Well, without further ado, let's start directly with this content.

module installation

The module that needs to be used this time is requeststhe module, and those who have not installed it can install it directly with pip.

environment

The environment used this time is Python3.8, and the editor is pycharm. Those who don’t have it can get it from the business card at the end of the article.

Show results

I only crawled one content here, and I also recorded a detailed video explanation, and took the video and code directly on the business card at the end of the article.

code display

modules used

import requests
import re
import json
import base64

send request

headers = {
    
    
    'cookie': 'support_webp=true; support_avif=true; csrf_session_id=76ceeb6d60b0fcd804de9be6e9693c54; s_v_web_id=verify_lefmeh66_SLWSXhCD_aZkd_4NEx_BgaI_hGUNbdQrHIpi; MONITOR_WEB_ID=56b4a269-39b6-4147-ab7c-9195b568c5e8; _tea_utm_cache_2018=undefined; passport_csrf_token=1a7dd3b7b20888e47197ea1d942e17d5; passport_csrf_token_default=1a7dd3b7b20888e47197ea1d942e17d5; passport_auth_status=121a29188cf1b9ecf308efbe3d0920c5%2C; passport_auth_status_ss=121a29188cf1b9ecf308efbe3d0920c5%2C; sid_guard=d75c6025dd5f4e3d658be37aad5f91b5%7C1677067151%7C3024000%7CWed%2C+29-Mar-2023+11%3A59%3A11+GMT; uid_tt=2f228913ef6379e66da0c3399feaa580; uid_tt_ss=2f228913ef6379e66da0c3399feaa580; sid_tt=d75c6025dd5f4e3d658be37aad5f91b5; sessionid=d75c6025dd5f4e3d658be37aad5f91b5; sessionid_ss=d75c6025dd5f4e3d658be37aad5f91b5; sid_ucp_v1=1.0.0-KGQ4Nzc4MjZiYWI1NWRmYTg5YjQyYmMyZjhmYjY1OWYyYzQzMDUyOGEKFAjo5IrYFxCPh9ifBhgYIAw4CEAFGgJobCIgZDc1YzYwMjVkZDVmNGUzZDY1OGJlMzdhYWQ1ZjkxYjU; ssid_ucp_v1=1.0.0-KGQ4Nzc4MjZiYWI1NWRmYTg5YjQyYmMyZjhmYjY1OWYyYzQzMDUyOGEKFAjo5IrYFxCPh9ifBhgYIAw4CEAFGgJobCIgZDc1YzYwMjVkZDVmNGUzZDY1OGJlMzdhYWQ1ZjkxYjU; __ac_nonce=063f604bf003948a3bad9; __ac_signature=_02B4Z6wo00f01SciCjgAAIDARCjKUZOPEREnAg6AACpBKsMzhMS3tmVlQF6xo9y4lk1.8f3BOblIBNOWtyn2ZteVVEle52JVejsr-gjz52x7fFDNHLhhWPSptiT342agtlzTUnp1SO2LBVZxb3; ixigua-a-s=3; odin_tt=5529039b6eb72ae52e2705d0db550fc06655c83bdbe61914be61c42152989c387a55ad2fa056636bfd1f880a86407f88; tt_scid=ORPDc-M6KS5eOmTgjaUrefaIL0yzO7y.HdHVQAZXahd0wmCZXjYo6rBN9gfC3xYF3559; ttwid=1%7CiWx9zpr2eLSL5pxwfW7PdpTasAnL2Tszm5jFlS0A_ac%7C1677067476%7C2d4446661479733452a7b0217ff6d0c80645ddd3f9f9e85f43547870d43654da; msToken=cSgsxZfj-6sePYrKBxT8cLGTA9Fe4h9FVEyqx2na-t6-TyoXHDL3Q_CQIxRvs9MrWsKeXvTH9OeSdsfiVqYu48Qcw-sEg2hF6sThIHy2b9J1L2mNumIx',
    'referer': 'https://www.ixigua.com/7188507369205301794?logTag=2bb3393d5b417ff0f1fa',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'
}
url = 'https://www.***.com/7188507369205301794?logTag=2bb3393d5b417ff0f1fa'
response = requests.get(url=url, headers=headers)

retrieve data

response.encoding = "utf-8"
html_data = response.text

Analytical data

json_str = re.findall('window._SSR_HYDRATED_DATA=(.*?)</script>', html_data)[0]
# 字典 undefined
json_str = json_str.replace('undefined', 'null')
json_data = json.loads(json_str)
video_list = json_data['anyVideo']['gidInformation']['packerData']['video']['videoResource']['normal']['video_list']
num = len(list(video_list.keys()))
main_url = video_list.get(f'video_{
      
      num}').get("main_url")
video_url = base64.b64decode(main_url).decode()
print(video_url)

save video/audio

video_data = requests.get(video_url, headers=headers).content
with open('1.mp4', mode='wb') as f:
    f.write(video_data)
audio_data = requests.get(audio_url).content
with open(f'{
      
      title}.mp3', mode='wb') as f:
    f.write(audio_data)
ffmpeg = r'ffmpeg -i ' + title + '.mp4 -i ' + title + '.mp3 -acodec copy -vcodec copy ' + title + '-out.mp4'
subprocess.run(ffmpeg)
os.remove(f'{
      
      title}.mp3')
os.remove(f'{
      
      title}.mp4')

at last

Well, that's all for today's sharing, if you like it, remember to like and bookmark, see you next time!

Guess you like

Origin blog.csdn.net/fei347795790/article/details/129182468