|
@@ -6,6 +6,7 @@ import random
|
|
|
import sys
|
|
|
import time
|
|
|
import uuid
|
|
|
+from datetime import datetime, timedelta
|
|
|
from hashlib import md5
|
|
|
|
|
|
from appium import webdriver
|
|
@@ -176,7 +177,6 @@ class ZFQZRecommendNew:
|
|
|
soup = BeautifulSoup(page_source, 'html.parser')
|
|
|
soup.prettify()
|
|
|
video_list = soup.findAll(name="wx-view", attrs={"class": "expose--adapt-parent"})
|
|
|
- index = index + 1
|
|
|
element_list = [i for i in video_list][index:]
|
|
|
return element_list[0]
|
|
|
|
|
@@ -186,7 +186,7 @@ class ZFQZRecommendNew:
|
|
|
|
|
|
self.check_to_applet(xpath='//*[@class="tags--tag tags--tag-0 tags--checked"]')
|
|
|
time.sleep(1)
|
|
|
- name = ["推荐", "搞笑", "大雪", "亲子"]
|
|
|
+ name = ["推荐", "春节"]
|
|
|
selected_text = random.choice(name)
|
|
|
try:
|
|
|
self.driver.find_element(By.XPATH, f"//wx-button[contains(., '{selected_text}')]").click()
|
|
@@ -265,6 +265,19 @@ class ZFQZRecommendNew:
|
|
|
Common.logger(self.log_type, self.crawler).info(f"{video_url_elements[0].get_attribute('src')}")
|
|
|
return video_url_elements[0].get_attribute('src')
|
|
|
|
|
|
+
|
|
|
+ def repeat_video(self,out_video_id):
|
|
|
+ current_time = datetime.now()
|
|
|
+ previous_day = current_time - timedelta(days=7)
|
|
|
+ formatted_time = previous_day.strftime("%Y-%m-%d")
|
|
|
+ sql = f""" select * from crawler_video where platform = "{self.platform}" and out_video_id="{out_video_id}" and create_time <= '{formatted_time}'; """
|
|
|
+ repeat_video = MysqlHelper.get_values(
|
|
|
+ log_type=self.log_type, crawler=self.platform, env=self.env, sql=sql, action=""
|
|
|
+ )
|
|
|
+ if repeat_video:
|
|
|
+ return False
|
|
|
+ return True
|
|
|
+
|
|
|
def get_video_info_2(self, video_element):
|
|
|
Common.logger(self.log_type, self.crawler).info(f"本轮已抓取{self.download_cnt}条视频\n")
|
|
|
# Common.logging(self.log_type, self.crawler, self.env, f"本轮已抓取{self.download_cnt}条视频\n")
|
|
@@ -277,39 +290,34 @@ class ZFQZRecommendNew:
|
|
|
Common.logger(self.log_type, self.crawler).info(f"第{self.count}条视频")
|
|
|
# 获取 trace_id, 并且把该 id 当做视频生命周期唯一索引
|
|
|
trace_id = self.crawler + str(uuid.uuid1())
|
|
|
- AliyunLogger.logging(
|
|
|
- code="1001",
|
|
|
- platform=self.platform,
|
|
|
- mode=self.log_type,
|
|
|
- env=self.env,
|
|
|
- trace_id=trace_id,
|
|
|
- message="扫描到一条视频",
|
|
|
- )
|
|
|
video_title = video_element.find("wx-view", class_="dynamic--title").text
|
|
|
play_str = video_element.find("wx-view", class_="dynamic--views").text
|
|
|
- like_str = video_element.findAll("wx-view", class_="dynamic--commerce-btn-text")[0].text
|
|
|
- comment_str = video_element.findAll("wx-view", class_="dynamic--commerce-btn-text")[1].text
|
|
|
+ # like_str = video_element.findAll("wx-view", class_="dynamic--commerce-btn-text")[0].text
|
|
|
+ # comment_str = video_element.findAll("wx-view", class_="dynamic--commerce-btn-text")[1].text
|
|
|
duration_str = video_element.find("wx-view", class_="dynamic--duration").text
|
|
|
user_name = video_element.find("wx-view", class_="dynamic--nick-top").text
|
|
|
avatar_url = video_element.find("wx-image", class_="avatar--avatar")["src"]
|
|
|
cover_url = video_element.find("wx-image", class_="dynamic--bg-image")["src"]
|
|
|
play_cnt = int(play_str.replace("+", "").replace("次播放", ""))
|
|
|
duration = int(duration_str.split(":")[0].strip()) * 60 + int(duration_str.split(":")[-1].strip())
|
|
|
- if "点赞" in like_str:
|
|
|
- like_cnt = 0
|
|
|
- elif "万" in like_str:
|
|
|
- like_cnt = int(like_str.split("万")[0]) * 10000
|
|
|
- else:
|
|
|
- like_cnt = int(like_str)
|
|
|
- if "评论" in comment_str:
|
|
|
- comment_cnt = 0
|
|
|
- elif "万" in comment_str:
|
|
|
- comment_cnt = int(comment_str.split("万")[0]) * 10000
|
|
|
- else:
|
|
|
- comment_cnt = int(comment_str)
|
|
|
+ # if "点赞" in like_str:
|
|
|
+ # like_cnt = 0
|
|
|
+ # elif "万" in like_str:
|
|
|
+ # like_cnt = int(like_str.split("万")[0]) * 10000
|
|
|
+ # else:
|
|
|
+ # like_cnt = int(like_str)
|
|
|
+ # if "评论" in comment_str:
|
|
|
+ # comment_cnt = 0
|
|
|
+ # elif "万" in comment_str:
|
|
|
+ # comment_cnt = int(comment_str.split("万")[0]) * 10000
|
|
|
+ # else:
|
|
|
+ # comment_cnt = int(comment_str)
|
|
|
out_video_id = md5(video_title.encode('utf8')).hexdigest()
|
|
|
out_user_id = md5(user_name.encode('utf8')).hexdigest()
|
|
|
-
|
|
|
+ repeat_id = self.repeat_video(out_video_id)
|
|
|
+ if False == repeat_id:
|
|
|
+ num = time.time()
|
|
|
+ out_video_id = out_video_id+str(num)
|
|
|
video_dict = {
|
|
|
"video_title": video_title,
|
|
|
"video_id": out_video_id,
|
|
@@ -318,10 +326,10 @@ class ZFQZRecommendNew:
|
|
|
"duration": duration,
|
|
|
"play_str": play_str,
|
|
|
"play_cnt": play_cnt,
|
|
|
- "like_str": like_str,
|
|
|
- "like_cnt": like_cnt,
|
|
|
- "comment_cnt": comment_cnt,
|
|
|
- "share_cnt": 0,
|
|
|
+ "like_str": "",
|
|
|
+ "like_cnt": 50,
|
|
|
+ "comment_cnt": 0,
|
|
|
+ "share_cnt": 50,
|
|
|
"user_name": user_name,
|
|
|
"user_id": out_user_id,
|
|
|
'publish_time_stamp': int(time.time()),
|
|
@@ -331,6 +339,15 @@ class ZFQZRecommendNew:
|
|
|
"cover_url": cover_url,
|
|
|
"session": f"zhufuquanzi-{int(time.time())}"
|
|
|
}
|
|
|
+ AliyunLogger.logging(
|
|
|
+ code="1001",
|
|
|
+ platform=self.platform,
|
|
|
+ mode=self.log_type,
|
|
|
+ env=self.env,
|
|
|
+ trace_id=trace_id,
|
|
|
+ message="扫描到一条视频",
|
|
|
+ data=video_dict
|
|
|
+ )
|
|
|
pipeline = PiaoQuanPipeline(
|
|
|
platform=self.crawler,
|
|
|
mode=self.log_type,
|
|
@@ -359,6 +376,9 @@ class ZFQZRecommendNew:
|
|
|
time.sleep(5)
|
|
|
return
|
|
|
video_dict['video_url'] = video_url
|
|
|
+ video_dict['like_cnt'] = 0
|
|
|
+ video_dict['share_cnt'] = 0
|
|
|
+
|
|
|
video_dict["platform"] = self.crawler
|
|
|
video_dict["strategy"] = self.log_type
|
|
|
video_dict["out_video_id"] = video_dict["video_id"]
|
|
@@ -366,6 +386,15 @@ class ZFQZRecommendNew:
|
|
|
video_dict["user_id"] = self.our_uid
|
|
|
video_dict["publish_time"] = video_dict["publish_time_str"]
|
|
|
self.mq.send_msg(video_dict)
|
|
|
+ AliyunLogger.logging(
|
|
|
+ code="1002",
|
|
|
+ platform=self.platform,
|
|
|
+ mode=self.log_type,
|
|
|
+ env=self.env,
|
|
|
+ trace_id=trace_id,
|
|
|
+ message="发送到ETL成功",
|
|
|
+ data=video_dict
|
|
|
+ )
|
|
|
self.download_cnt += 1
|
|
|
self.driver.press_keycode(AndroidKey.BACK)
|
|
|
time.sleep(5)
|
|
@@ -373,9 +402,9 @@ class ZFQZRecommendNew:
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- rule_dict1 = {"period": {"min": 1, "max": 365},
|
|
|
- "duration": {"min": 1, "max": 1800},
|
|
|
- "favorite_cnt": {"min": 1, "max": 0},
|
|
|
- "videos_cnt": {"min": 1, "max": 20},
|
|
|
- "share_cnt": {"min": 1, "max": 0}}
|
|
|
+ rule_dict1 = {"period": {"min": 0, "max": 0},
|
|
|
+ "duration": {"min": 1, "max": 0},
|
|
|
+ "favorite_cnt": {"min": 0, "max": 0},
|
|
|
+ "videos_cnt": {"min": 0, "max": 0},
|
|
|
+ "share_cnt": {"min": 0, "max": 0}}
|
|
|
ZFQZRecommendNew("recommend", "zhufuquanzi", "dev", rule_dict1, 6267141)
|