|
@@ -103,9 +103,10 @@ class Follow:
|
|
@classmethod
|
|
@classmethod
|
|
def get_out_user_info(cls, log_type, crawler, out_uid):
|
|
def get_out_user_info(cls, log_type, crawler, out_uid):
|
|
try:
|
|
try:
|
|
- headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41',
|
|
|
|
- 'referer': f'https://www.ixigua.com/home/{out_uid}',
|
|
|
|
- 'Cookie': f'ixigua-a-s=1; support_webp=true; support_avif=false; csrf_session_id=a5355d954d3c63ed1ba35faada452b4d; __ac_signature={cls.random_signature()}; MONITOR_WEB_ID=67cb5099-a022-4ec3-bb8e-c4de6ba51dd0; s_v_web_id=verify_lef4i99x_32SosrdH_Qrtk_4LJn_8S7q_fhu16xe3s8ZV; tt_scid=QLJjPuHf6wxVqu6IIq6gHiJXQpVrCwrdhjH2zpm7-E3ZniE1RXBcP6M8b41FJOdo41e1; ttwid=1%7CHHtv2QqpSGuSu8r-zXF1QoWsvjmNi1SJrqOrZzg-UCY%7C1677047013%7C5866a444e5ae10a9df8c11551db75010fb77b657f214ccf84e503fae8d313d09; msToken=PerXJcDdIsZ6zXkGITsftXX4mDaVaW21GuqtzSVdctH46oXXT2GcELIs9f0XW2hunRzP6KVHLZaYElRvNYflLKUXih7lC27XKxs3HjdZiXPK9NQaoKbLfA==; ixigua-a-s=1',}
|
|
|
|
|
|
+ headers = {
|
|
|
|
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41',
|
|
|
|
+ 'referer': f'https://www.ixigua.com/home/{out_uid}',
|
|
|
|
+ 'Cookie': f'ixigua-a-s=1; support_webp=true; support_avif=false; csrf_session_id=a5355d954d3c63ed1ba35faada452b4d; __ac_signature={cls.random_signature()}; MONITOR_WEB_ID=67cb5099-a022-4ec3-bb8e-c4de6ba51dd0; s_v_web_id=verify_lef4i99x_32SosrdH_Qrtk_4LJn_8S7q_fhu16xe3s8ZV; tt_scid=QLJjPuHf6wxVqu6IIq6gHiJXQpVrCwrdhjH2zpm7-E3ZniE1RXBcP6M8b41FJOdo41e1; ttwid=1%7CHHtv2QqpSGuSu8r-zXF1QoWsvjmNi1SJrqOrZzg-UCY%7C1677047013%7C5866a444e5ae10a9df8c11551db75010fb77b657f214ccf84e503fae8d313d09; msToken=PerXJcDdIsZ6zXkGITsftXX4mDaVaW21GuqtzSVdctH46oXXT2GcELIs9f0XW2hunRzP6KVHLZaYElRvNYflLKUXih7lC27XKxs3HjdZiXPK9NQaoKbLfA==; ixigua-a-s=1', }
|
|
url = f"https://www.ixigua.com/home/{out_uid}"
|
|
url = f"https://www.ixigua.com/home/{out_uid}"
|
|
urllib3.disable_warnings()
|
|
urllib3.disable_warnings()
|
|
s = requests.session()
|
|
s = requests.session()
|
|
@@ -114,20 +115,23 @@ class Follow:
|
|
s.mount('https://', HTTPAdapter(max_retries=3))
|
|
s.mount('https://', HTTPAdapter(max_retries=3))
|
|
response = s.get(url=url, headers=headers, proxies=Common.tunnel_proxies(), verify=False, timeout=5).text
|
|
response = s.get(url=url, headers=headers, proxies=Common.tunnel_proxies(), verify=False, timeout=5).text
|
|
html = etree.HTML(response)
|
|
html = etree.HTML(response)
|
|
- out_follow_str = html.xpath('//div[@class="userDetailV3__header__detail2"]/*[1]/span')[0].text.encode('raw_unicode_escape').decode()
|
|
|
|
- out_fans_str = html.xpath('//div[@class="userDetailV3__header__detail2"]/*[2]/span')[0].text.encode('raw_unicode_escape').decode()
|
|
|
|
- out_like_str = html.xpath('//div[@class="userDetailV3__header__detail2"]/*[3]/span')[0].text.encode('raw_unicode_escape').decode()
|
|
|
|
|
|
+ out_follow_str = html.xpath('//div[@class="userDetailV3__header__detail2"]/*[1]/span')[0].text.encode(
|
|
|
|
+ 'raw_unicode_escape').decode()
|
|
|
|
+ out_fans_str = html.xpath('//div[@class="userDetailV3__header__detail2"]/*[2]/span')[0].text.encode(
|
|
|
|
+ 'raw_unicode_escape').decode()
|
|
|
|
+ out_like_str = html.xpath('//div[@class="userDetailV3__header__detail2"]/*[3]/span')[0].text.encode(
|
|
|
|
+ 'raw_unicode_escape').decode()
|
|
out_avatar_url = f"""https:{html.xpath('//span[@class="component-avatar__inner"]//img/@src')[0]}"""
|
|
out_avatar_url = f"""https:{html.xpath('//span[@class="component-avatar__inner"]//img/@src')[0]}"""
|
|
if "万" in out_follow_str:
|
|
if "万" in out_follow_str:
|
|
- out_follow = int(float(out_follow_str.split("万")[0])*10000)
|
|
|
|
|
|
+ out_follow = int(float(out_follow_str.split("万")[0]) * 10000)
|
|
else:
|
|
else:
|
|
out_follow = int(out_follow_str.replace(",", ""))
|
|
out_follow = int(out_follow_str.replace(",", ""))
|
|
if "万" in out_fans_str:
|
|
if "万" in out_fans_str:
|
|
- out_fans = int(float(out_fans_str.split("万")[0])*10000)
|
|
|
|
|
|
+ out_fans = int(float(out_fans_str.split("万")[0]) * 10000)
|
|
else:
|
|
else:
|
|
out_fans = int(out_fans_str.replace(",", ""))
|
|
out_fans = int(out_fans_str.replace(",", ""))
|
|
if "万" in out_like_str:
|
|
if "万" in out_like_str:
|
|
- out_like = int(float(out_like_str.split("万")[0])*10000)
|
|
|
|
|
|
+ out_like = int(float(out_like_str.split("万")[0]) * 10000)
|
|
else:
|
|
else:
|
|
out_like = int(out_like_str.replace(",", ""))
|
|
out_like = int(out_like_str.replace(",", ""))
|
|
out_user_dict = {
|
|
out_user_dict = {
|
|
@@ -153,7 +157,7 @@ class Follow:
|
|
continue
|
|
continue
|
|
our_user_list = []
|
|
our_user_list = []
|
|
for i in range(1, len(user_sheet)):
|
|
for i in range(1, len(user_sheet)):
|
|
- # for i in range(428, len(user_sheet)):
|
|
|
|
|
|
+ # for i in range(428, len(user_sheet)):
|
|
out_uid = user_sheet[i][2]
|
|
out_uid = user_sheet[i][2]
|
|
user_name = user_sheet[i][3]
|
|
user_name = user_sheet[i][3]
|
|
our_uid = user_sheet[i][6]
|
|
our_uid = user_sheet[i][6]
|
|
@@ -181,10 +185,12 @@ class Follow:
|
|
"platform": cls.platform,
|
|
"platform": cls.platform,
|
|
"tag": cls.tag,
|
|
"tag": cls.tag,
|
|
}
|
|
}
|
|
- our_user_dict = getUser.create_user(log_type=log_type, crawler=crawler, out_user_dict=out_user_dict, env=env, machine=machine)
|
|
|
|
|
|
+ our_user_dict = getUser.create_user(log_type=log_type, crawler=crawler,
|
|
|
|
+ out_user_dict=out_user_dict, env=env, machine=machine)
|
|
our_uid = our_user_dict['our_uid']
|
|
our_uid = our_user_dict['our_uid']
|
|
our_user_link = our_user_dict['our_user_link']
|
|
our_user_link = our_user_dict['our_user_link']
|
|
- Feishu.update_values(log_type, crawler, sheetid, f'G{i + 1}:H{i + 1}', [[our_uid, our_user_link]])
|
|
|
|
|
|
+ Feishu.update_values(log_type, crawler, sheetid, f'G{i + 1}:H{i + 1}',
|
|
|
|
+ [[our_uid, our_user_link]])
|
|
Common.logger(log_type, crawler).info(f'站内用户信息写入飞书成功!\n')
|
|
Common.logger(log_type, crawler).info(f'站内用户信息写入飞书成功!\n')
|
|
our_user_list.append(our_user_dict)
|
|
our_user_list.append(our_user_dict)
|
|
else:
|
|
else:
|
|
@@ -301,7 +307,8 @@ class Follow:
|
|
# max_retries=3 重试3次
|
|
# max_retries=3 重试3次
|
|
s.mount('http://', HTTPAdapter(max_retries=3))
|
|
s.mount('http://', HTTPAdapter(max_retries=3))
|
|
s.mount('https://', HTTPAdapter(max_retries=3))
|
|
s.mount('https://', HTTPAdapter(max_retries=3))
|
|
- response = s.get(url=url, headers=headers, params=params, cookies=cookies, verify=False, proxies=Common.tunnel_proxies(), timeout=5)
|
|
|
|
|
|
+ response = s.get(url=url, headers=headers, params=params, cookies=cookies, verify=False,
|
|
|
|
+ proxies=Common.tunnel_proxies(), timeout=5)
|
|
response.close()
|
|
response.close()
|
|
if 'data' not in response.json() or response.json()['data'] == '':
|
|
if 'data' not in response.json() or response.json()['data'] == '':
|
|
Common.logger(log_type, crawler).warning('get_video_info: response: {}', response)
|
|
Common.logger(log_type, crawler).warning('get_video_info: response: {}', response)
|
|
@@ -316,7 +323,8 @@ class Follow:
|
|
video_url_dict["video_height"] = 0
|
|
video_url_dict["video_height"] = 0
|
|
|
|
|
|
elif 'dash_120fps' in video_info['videoResource']:
|
|
elif 'dash_120fps' in video_info['videoResource']:
|
|
- if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in video_info['videoResource']['dash_120fps']['video_list']:
|
|
|
|
|
|
+ if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['video_list']:
|
|
video_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
|
|
video_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
@@ -335,7 +343,8 @@ class Follow:
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_height"] = video_height
|
|
video_url_dict["video_height"] = video_height
|
|
- elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_3' in video_info['videoResource']['dash_120fps']['video_list']:
|
|
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_3' in \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['video_list']:
|
|
video_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
|
|
video_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
@@ -354,7 +363,8 @@ class Follow:
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_height"] = video_height
|
|
video_url_dict["video_height"] = video_height
|
|
- elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in video_info['videoResource']['dash_120fps']['video_list']:
|
|
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['video_list']:
|
|
video_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
|
|
video_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
@@ -373,7 +383,8 @@ class Follow:
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_height"] = video_height
|
|
video_url_dict["video_height"] = video_height
|
|
- elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in video_info['videoResource']['dash_120fps']['video_list']:
|
|
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['video_list']:
|
|
video_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
|
|
video_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
@@ -396,11 +407,17 @@ class Follow:
|
|
elif 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
|
|
elif 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
|
|
and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
|
|
and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
|
|
and 'dynamic_audio_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
|
|
and 'dynamic_audio_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
|
|
- and len(video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
|
|
|
|
- and len(video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
|
|
|
|
|
|
+ and len(
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
|
|
|
|
+ and len(
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
|
|
|
|
|
|
- video_url = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['backup_url_1']
|
|
|
|
- audio_url = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1]['backup_url_1']
|
|
|
|
|
|
+ video_url = \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ audio_url = \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
video_url += '=='
|
|
video_url += '=='
|
|
elif len(video_url) % 3 == 2:
|
|
elif len(video_url) % 3 == 2:
|
|
@@ -411,8 +428,10 @@ class Follow:
|
|
audio_url += '='
|
|
audio_url += '='
|
|
video_url = base64.b64decode(video_url).decode('utf8')
|
|
video_url = base64.b64decode(video_url).decode('utf8')
|
|
audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
- video_width = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['vwidth']
|
|
|
|
- video_height = video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['vheight']
|
|
|
|
|
|
+ video_width = \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['vwidth']
|
|
|
|
+ video_height = \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1]['vheight']
|
|
video_url_dict["video_url"] = video_url
|
|
video_url_dict["video_url"] = video_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_width"] = video_width
|
|
@@ -424,7 +443,8 @@ class Follow:
|
|
video_url_dict["video_height"] = 0
|
|
video_url_dict["video_height"] = 0
|
|
|
|
|
|
elif 'dash' in video_info['videoResource']:
|
|
elif 'dash' in video_info['videoResource']:
|
|
- if "video_list" in video_info['videoResource']['dash'] and 'video_4' in video_info['videoResource']['dash']['video_list']:
|
|
|
|
|
|
+ if "video_list" in video_info['videoResource']['dash'] and 'video_4' in \
|
|
|
|
+ video_info['videoResource']['dash']['video_list']:
|
|
video_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
|
|
video_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
@@ -443,7 +463,8 @@ class Follow:
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_height"] = video_height
|
|
video_url_dict["video_height"] = video_height
|
|
- elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in video_info['videoResource']['dash']['video_list']:
|
|
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in \
|
|
|
|
+ video_info['videoResource']['dash']['video_list']:
|
|
video_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
|
|
video_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
@@ -462,7 +483,8 @@ class Follow:
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_height"] = video_height
|
|
video_url_dict["video_height"] = video_height
|
|
- elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in video_info['videoResource']['dash']['video_list']:
|
|
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in \
|
|
|
|
+ video_info['videoResource']['dash']['video_list']:
|
|
video_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
|
|
video_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
@@ -481,7 +503,8 @@ class Follow:
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_height"] = video_height
|
|
video_url_dict["video_height"] = video_height
|
|
- elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in video_info['videoResource']['dash']['video_list']:
|
|
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in \
|
|
|
|
+ video_info['videoResource']['dash']['video_list']:
|
|
video_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
|
|
video_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
|
|
audio_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
@@ -507,8 +530,10 @@ class Follow:
|
|
and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list']) != 0 \
|
|
and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list']) != 0 \
|
|
and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list']) != 0:
|
|
and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list']) != 0:
|
|
|
|
|
|
- video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['backup_url_1']
|
|
|
|
- audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1]['backup_url_1']
|
|
|
|
|
|
+ video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
if len(video_url) % 3 == 1:
|
|
if len(video_url) % 3 == 1:
|
|
video_url += '=='
|
|
video_url += '=='
|
|
elif len(video_url) % 3 == 2:
|
|
elif len(video_url) % 3 == 2:
|
|
@@ -519,8 +544,10 @@ class Follow:
|
|
audio_url += '='
|
|
audio_url += '='
|
|
video_url = base64.b64decode(video_url).decode('utf8')
|
|
video_url = base64.b64decode(video_url).decode('utf8')
|
|
audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
- video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['vwidth']
|
|
|
|
- video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['vheight']
|
|
|
|
|
|
+ video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'vheight']
|
|
video_url_dict["video_url"] = video_url
|
|
video_url_dict["video_url"] = video_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["audio_url"] = audio_url
|
|
video_url_dict["video_width"] = video_width
|
|
video_url_dict["video_width"] = video_width
|
|
@@ -676,28 +703,16 @@ class Follow:
|
|
'_signature': signature,
|
|
'_signature': signature,
|
|
}
|
|
}
|
|
headers = {
|
|
headers = {
|
|
- # 'authority': 'www.ixigua.com',
|
|
|
|
- # 'accept': 'application/json, text/plain, */*',
|
|
|
|
- # 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
|
|
|
|
- # 'cache-control': 'no-cache',
|
|
|
|
- # 'cookie': f'MONITOR_WEB_ID=7168304743566296612; __ac_signature={signature}; ixigua-a-s=1; support_webp=true; support_avif=false; csrf_session_id=a5355d954d3c63ed1ba35faada452b4d; msToken=G0eRzNkw189a8TLaXjc6nTHVMQwh9XcxVAqTbGKi7iPJdQcLwS3-XRrJ3MZ7QBfqErpxp3EX1WtvWOIcZ3NIgr41hgcd-v64so_RRj3YCRw1UsKW8mIssNLlIMspsg==; tt_scid=o4agqz7u9SKPwfBoPt6S82Cw0q.9KDtqmNe0JHxMqmpxNHQWq1BmrQdgVU6jEoX7ed99; ttwid=1%7CHHtv2QqpSGuSu8r-zXF1QoWsvjmNi1SJrqOrZzg-UCY%7C1676618894%7Cee5ad95378275f282f230a7ffa9947ae7eff40d0829c5a2568672a6dc90a1c96; ixigua-a-s=1',
|
|
|
|
- # 'pragma': 'no-cache',
|
|
|
|
'referer': f'https://www.ixigua.com/home/{out_uid}/video/?preActiveKey=hotsoon&list_entrance=userdetail',
|
|
'referer': f'https://www.ixigua.com/home/{out_uid}/video/?preActiveKey=hotsoon&list_entrance=userdetail',
|
|
- # 'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"',
|
|
|
|
- # 'sec-ch-ua-mobile': '?0',
|
|
|
|
- # 'sec-ch-ua-platform': '"macOS"',
|
|
|
|
- # 'sec-fetch-dest': 'empty',
|
|
|
|
- # 'sec-fetch-mode': 'cors',
|
|
|
|
- # 'sec-fetch-site': 'same-origin',
|
|
|
|
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41',
|
|
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.41',
|
|
- # 'x-secsdk-csrf-token': '00010000000119e3f9454d1dcbb288704cda1960f241e2d19bd21f2fd283520c3615a990ac5a17448bfbb902a249'
|
|
|
|
}
|
|
}
|
|
urllib3.disable_warnings()
|
|
urllib3.disable_warnings()
|
|
s = requests.session()
|
|
s = requests.session()
|
|
# max_retries=3 重试3次
|
|
# max_retries=3 重试3次
|
|
s.mount('http://', HTTPAdapter(max_retries=3))
|
|
s.mount('http://', HTTPAdapter(max_retries=3))
|
|
s.mount('https://', HTTPAdapter(max_retries=3))
|
|
s.mount('https://', HTTPAdapter(max_retries=3))
|
|
- response = s.get(url=url, headers=headers, params=params, proxies=Common.tunnel_proxies(), verify=False, timeout=5)
|
|
|
|
|
|
+ response = s.get(url=url, headers=headers, params=params, proxies=Common.tunnel_proxies(), verify=False,
|
|
|
|
+ timeout=5)
|
|
response.close()
|
|
response.close()
|
|
cls.offset += 30
|
|
cls.offset += 30
|
|
if response.status_code != 200:
|
|
if response.status_code != 200:
|
|
@@ -720,7 +735,7 @@ class Follow:
|
|
video_title = 0
|
|
video_title = 0
|
|
else:
|
|
else:
|
|
video_title = videoList[i]['title'].strip().replace('手游', '') \
|
|
video_title = videoList[i]['title'].strip().replace('手游', '') \
|
|
- .replace('/', '').replace('\/', '').replace('\n', '').replace('"' ,'').replace("'", '')
|
|
|
|
|
|
+ .replace('/', '').replace('\/', '').replace('\n', '').replace('"', '').replace("'", '')
|
|
|
|
|
|
# video_id
|
|
# video_id
|
|
if 'video_id' not in videoList[i]:
|
|
if 'video_id' not in videoList[i]:
|
|
@@ -809,7 +824,8 @@ class Follow:
|
|
elif 'url' in videoList[i]['video_detail_info']['detail_video_large_image']:
|
|
elif 'url' in videoList[i]['video_detail_info']['detail_video_large_image']:
|
|
cover_url = videoList[i]['video_detail_info']['detail_video_large_image']['url']
|
|
cover_url = videoList[i]['video_detail_info']['detail_video_large_image']['url']
|
|
else:
|
|
else:
|
|
- cover_url = videoList[i]['video_detail_info']['detail_video_large_image']['url_list'][0]['url']
|
|
|
|
|
|
+ cover_url = videoList[i]['video_detail_info']['detail_video_large_image']['url_list'][0][
|
|
|
|
+ 'url']
|
|
|
|
|
|
Common.logger(log_type, crawler).info(f'---开始读取规则---')
|
|
Common.logger(log_type, crawler).info(f'---开始读取规则---')
|
|
rule_dict = cls.get_rule(log_type, crawler)
|
|
rule_dict = cls.get_rule(log_type, crawler)
|
|
@@ -817,10 +833,13 @@ class Follow:
|
|
|
|
|
|
if gid == 0 or video_id == 0 or cover_url == 0:
|
|
if gid == 0 or video_id == 0 or cover_url == 0:
|
|
Common.logger(log_type, crawler).info('无效视频\n')
|
|
Common.logger(log_type, crawler).info('无效视频\n')
|
|
- elif is_top is True and int(time.time()) - int(publish_time) > 3600 * 24 * rule_dict['publish_time']:
|
|
|
|
- Common.logger(log_type, crawler).info(f'置顶视频,且发布时间:{publish_time_str} 超过{rule_dict["publish_time"]}天\n')
|
|
|
|
|
|
+ elif is_top is True and int(time.time()) - int(publish_time) > 3600 * 24 * rule_dict[
|
|
|
|
+ 'publish_time']:
|
|
|
|
+ Common.logger(log_type, crawler).info(
|
|
|
|
+ f'置顶视频,且发布时间:{publish_time_str} 超过{rule_dict["publish_time"]}天\n')
|
|
elif int(time.time()) - int(publish_time) > 3600 * 24 * rule_dict['publish_time']:
|
|
elif int(time.time()) - int(publish_time) > 3600 * 24 * rule_dict['publish_time']:
|
|
- Common.logger(log_type, crawler).info(f'发布时间:{publish_time_str}超过{rule_dict["publish_time"]}天\n')
|
|
|
|
|
|
+ Common.logger(log_type, crawler).info(
|
|
|
|
+ f'发布时间:{publish_time_str}超过{rule_dict["publish_time"]}天\n')
|
|
cls.offset = 0
|
|
cls.offset = 0
|
|
return
|
|
return
|
|
else:
|
|
else:
|
|
@@ -876,7 +895,8 @@ class Follow:
|
|
try:
|
|
try:
|
|
if cls.download_rule(video_dict, rule_dict) is False:
|
|
if cls.download_rule(video_dict, rule_dict) is False:
|
|
Common.logger(log_type, crawler).info('不满足抓取规则\n')
|
|
Common.logger(log_type, crawler).info('不满足抓取规则\n')
|
|
- elif any(word if word in video_dict['video_title'] else False for word in cls.filter_words(log_type, crawler)) is True:
|
|
|
|
|
|
+ elif any(word if word in video_dict['video_title'] else False for word in
|
|
|
|
+ cls.filter_words(log_type, crawler)) is True:
|
|
Common.logger(log_type, crawler).info('标题已中过滤词:{}\n', video_dict['video_title'])
|
|
Common.logger(log_type, crawler).info('标题已中过滤词:{}\n', video_dict['video_title'])
|
|
elif cls.repeat_video(log_type, crawler, video_dict['video_id'], env, machine) != 0:
|
|
elif cls.repeat_video(log_type, crawler, video_dict['video_id'], env, machine) != 0:
|
|
Common.logger(log_type, crawler).info('视频已下载\n')
|
|
Common.logger(log_type, crawler).info('视频已下载\n')
|
|
@@ -890,11 +910,14 @@ class Follow:
|
|
# Common.logger(log_type, crawler).info('视频已存在\n')
|
|
# Common.logger(log_type, crawler).info('视频已存在\n')
|
|
else:
|
|
else:
|
|
# 下载视频
|
|
# 下载视频
|
|
- Common.download_method(log_type=log_type, crawler=crawler, text='xigua_video', title=video_dict['video_title'], url=video_dict['video_url'])
|
|
|
|
|
|
+ Common.download_method(log_type=log_type, crawler=crawler, text='xigua_video',
|
|
|
|
+ title=video_dict['video_title'], url=video_dict['video_url'])
|
|
# 下载音频
|
|
# 下载音频
|
|
- Common.download_method(log_type=log_type, crawler=crawler, text='xigua_audio', title=video_dict['video_title'], url=video_dict['audio_url'])
|
|
|
|
|
|
+ Common.download_method(log_type=log_type, crawler=crawler, text='xigua_audio',
|
|
|
|
+ title=video_dict['video_title'], url=video_dict['audio_url'])
|
|
# 合成音视频
|
|
# 合成音视频
|
|
- Common.video_compose(log_type=log_type, crawler=crawler, video_dir=f"./{crawler}/videos/{video_dict['video_title']}")
|
|
|
|
|
|
+ Common.video_compose(log_type=log_type, crawler=crawler,
|
|
|
|
+ video_dir=f"./{crawler}/videos/{video_dict['video_title']}")
|
|
md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
|
|
md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
|
|
if os.path.getsize(f"./{crawler}/videos/{md_title}/video.mp4") == 0:
|
|
if os.path.getsize(f"./{crawler}/videos/{md_title}/video.mp4") == 0:
|
|
# 删除视频文件夹
|
|
# 删除视频文件夹
|
|
@@ -908,7 +931,8 @@ class Follow:
|
|
# shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
|
|
# shutil.rmtree(f"./{crawler}/videos/{video_dict['video_title']}")
|
|
# return
|
|
# return
|
|
# 下载封面
|
|
# 下载封面
|
|
- Common.download_method(log_type=log_type, crawler=crawler, text='cover', title=video_dict['video_title'], url=video_dict['cover_url'])
|
|
|
|
|
|
+ Common.download_method(log_type=log_type, crawler=crawler, text='cover',
|
|
|
|
+ title=video_dict['video_title'], url=video_dict['cover_url'])
|
|
# 保存视频信息至txt
|
|
# 保存视频信息至txt
|
|
Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
|
|
Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
|
|
|
|
|
|
@@ -996,30 +1020,24 @@ class Follow:
|
|
|
|
|
|
@classmethod
|
|
@classmethod
|
|
def get_follow_videos(cls, log_type, crawler, strategy, oss_endpoint, env, machine):
|
|
def get_follow_videos(cls, log_type, crawler, strategy, oss_endpoint, env, machine):
|
|
- try:
|
|
|
|
- # user_list = cls.get_user_list(log_type=log_type, crawler=crawler, sheetid="5tlTYB", env=env, machine=machine)
|
|
|
|
- user_list = get_user_from_mysql(log_type, crawler, crawler, env)
|
|
|
|
-
|
|
|
|
- for user in user_list:
|
|
|
|
- spider_link = user["spider_link"]
|
|
|
|
- out_uid = spider_link.split('/')[-1]
|
|
|
|
- user_name = user["nick_name"]
|
|
|
|
- our_uid = user["media_id"]
|
|
|
|
|
|
+ user_list = get_user_from_mysql(log_type, crawler, crawler, env)
|
|
|
|
+ for user in user_list:
|
|
|
|
+ spider_link = user["spider_link"]
|
|
|
|
+ out_uid = spider_link.split('/')[-1]
|
|
|
|
+ user_name = user["nick_name"]
|
|
|
|
+ our_uid = user["media_id"]
|
|
|
|
|
|
- Common.logger(log_type, crawler).info(f"开始抓取 {user_name} 用户主页视频\n")
|
|
|
|
- cls.get_videolist(log_type=log_type,
|
|
|
|
- crawler=crawler,
|
|
|
|
- strategy=strategy,
|
|
|
|
- our_uid=our_uid,
|
|
|
|
- out_uid=out_uid,
|
|
|
|
- oss_endpoint=oss_endpoint,
|
|
|
|
- env=env,
|
|
|
|
- machine=machine)
|
|
|
|
- cls.offset = 0
|
|
|
|
- time.sleep(1)
|
|
|
|
- except Exception as e:
|
|
|
|
- Common.logger(log_type, crawler).error(f"get_follow_videos:{e}\n")
|
|
|
|
|
|
+ Common.logger(log_type, crawler).info(f"开始抓取 {user_name} 用户主页视频\n")
|
|
|
|
+ cls.get_videolist(log_type=log_type,
|
|
|
|
+ crawler=crawler,
|
|
|
|
+ strategy=strategy,
|
|
|
|
+ our_uid=our_uid,
|
|
|
|
+ out_uid=out_uid,
|
|
|
|
+ oss_endpoint=oss_endpoint,
|
|
|
|
+ env=env,
|
|
|
|
+ machine=machine)
|
|
|
|
+ cls.offset = 0
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
- Follow.get_follow_videos('follow','xigua','定向抓取策略', 'inner','prod', 'aliyun')
|
|
|
|
|
|
+ Follow.get_follow_videos('follow', 'xigua', '定向抓取策略', 'inner', 'prod', 'aliyun')
|