一键生成微信对话视频工具,省时省力抢占先机

[复制链接]
查看34 | 回复0 | 2024-9-29 22:06:00 | 显示全部楼层 |阅读模式
在抖音或视频号平台,你是否被那些引人捧腹、妙趣横生的微信对话短视频所吸引?此类视频播放量巨大,同时也可产生丰厚的回报。本文将揭示此类短视频的制作奥秘,并指导如何运用一键生成工具轻松打造个人爆款视频。

微信对话视频的火爆现象

微信对话视频在抖音和视频号上的广受欢迎,得益于其内容的趣味性和贴近生活。这类视频因共鸣和幽默感深受观众喜爱,播放量之所以飙升,在于其在短时内迅速吸引海量观众,实现病毒式扩散。

该视频制作的原理并不复杂:依托高播放量嵌入商品链接,用户通过链接购买即可使制作者获得佣金。此模式既使创作者收益颇丰,亦使观众在娱乐之余不经意间参与了消费。

传统制作方法的繁琐与低效

制作微信对话视频的传统方式繁复耗时。过程涉及线上搜索对话素材,利用模拟器生成对话图片,并对这些图片进行编辑,最终输出视频。这些步骤不仅占用大量时间,且每个视频制作大多为机械重复,效率低下。

恶劣的是,此类反复性劳动极易引发厌倦情绪。即便觅得有聊的对话素材,制作工作的繁琐性仍可能导致创作动力的丧失。据此,众多有意制作此类视频者,常因制作难度过大而放弃。

一键生成工具的诞生



为简化传统制作流程的复杂性,技术专家们研发了简易操作的手机微信对话视频生成器。此应用使得创建微信对话视频变得史无前例地便捷。操作界面简洁直观,无需复杂步骤,便能够迅速构建出完整的视频文件,大幅节省时间和精力。

开发此系列工具的过程中,融合了多项尖端技术。例如,利用爬虫技术从诸如百度等网站抓取图片,借助OCR识别技术解析图像中的文本,通过模拟微信对话的工具创建逼真的交互界面,而Server服务与Playwright自动化技术则协同工作,将上述功能整合,最终产出视频内容。

技术背后的复杂性

<p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;">    <span style="display: block;background: url("https://mmbiz.qpic.cn/mmbiz_svg/zZSYtpeVianTCibtUklhlFBD1Vsiabs2syn5mhW6hfq769uT1wnbSBTiaEsYnxhvPygrD7MHTb11oN7MeIiaXOTwicRWxmmCQ3pSm9/640?wx_fmt=svg") 10px 10px / 40px no-repeat rgb(250, 250, 250);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;"></span><code style="overflow-x: auto;padding: 16px;color: #383a42;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #fafafa;border-radius: 5px;">url = (    <span style="color: #50a14f;line-height: 26px;">"https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj"</span><br  />    <span style="color: #50a14f;line-height: 26px;">"&ct=201326592&is=&fp=result&queryWord=%s&cl=2&lm=-1&ie=utf-8&oe=utf-8"</span><br  />    <span style="color: #50a14f;line-height: 26px;">"&adpicid=&st=-1&z=&ic=&hd=&latest=&copyright=&word=%s&s=&se=&tab=&width=&height=&face=0"</span><br  />    <span style="color: #50a14f;line-height: 26px;">"&istype=2&qc=&nc=1&fr=&expermode=&force=&pn=%s&rn=%d&gsm=1e&1594447993172="</span><br  />    % (search, search, str(pn), self.__per_page)<br  />)<br  /><span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 设置header防403</span><br  />try:<br  />    time.sleep(self.time_sleep)<br  />    req = urllib.request.Request(url=url, headers=self.headers)<br  />    page = urllib.request.urlopen(req)<br  />    self.headers[<span style="color: #50a14f;line-height: 26px;">"Cookie"</span>] = self.handle_baidu_cookie(<br  />        self.headers[<span style="color: #50a14f;line-height: 26px;">"Cookie"</span>], page.info().get_all(<span style="color: #50a14f;line-height: 26px;">"Set-Cookie"</span>)<br  />    )<br  />    rsp = page.read()<br  />    page.close()<br  />except UnicodeDecodeError as e:<br  />    self.logger.error(e)<br  />    self.logger.error(<span style="color: #50a14f;line-height: 26px;">"-----UnicodeDecodeErrorurl:"</span>, url)<br  /></code></pre></p>
尽管一键生成技术简化了微信对话视频的制作流程,其背后涉及的技术实现却相对复杂。此类工具的开发需综合运用多种技术,涵盖数据爬取、光学字符识别、微信对话模拟、服务器编程、自动化脚本及图形用户界面等。每种技术均具备其复杂性,对开发者的技术实力提出了严格要求。

开发者需掌握网络爬虫规范以防范封禁,精通图像处理技术以运用OCR识别,精确理解微信界面及交互逻辑以构建模拟对话工具。融合这些技术,方可实现一键生成微信对话视频的功能。

<p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;">    <span style="display: block;background: url("https://mmbiz.qpic.cn/mmbiz_svg/zZSYtpeVianTCibtUklhlFBD1Vsiabs2syn5mhW6hfq769uT1wnbSBTiaEsYnxhvPygrD7MHTb11oN7MeIiaXOTwicRWxmmCQ3pSm9/640?wx_fmt=svg") 10px 10px / 40px no-repeat rgb(250, 250, 250);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;"></span><code style="overflow-x: auto;padding: 16px;color: #383a42;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #fafafa;border-radius: 5px;">self.model = CnOcr(<br  />            det_model_name=<span style="color: #50a14f;line-height: 26px;">"ch_PP-OCRv3_det"</span>,<br  />        )<br  />out = self.model.ocr(<br  />    cv2.imdecode(self.read_file(f), -1),<br  />)<br  /><span style="color: #a626a4;line-height: 26px;">for</span> i <span style="color: #a626a4;line-height: 26px;">in</span> out:<br  />    i[<span style="color: #50a14f;line-height: 26px;">"score"</span>] = <span style="color: #c18401;line-height: 26px;">float</span>(i[<span style="color: #50a14f;line-height: 26px;">"score"</span>])<br  />    i[<span style="color: #50a14f;line-height: 26px;">"position"</span>] = i[<span style="color: #50a14f;line-height: 26px;">"position"</span>].astype(<span style="color: #c18401;line-height: 26px;">float</span>).tolist()<br  />    target_path.joinpath(file_name + <span style="color: #50a14f;line-height: 26px;">".json"</span>).write_text(<br  />        json.dumps(out, ensure_ascii=False, indent=4)<br  />    )<br  /></code></pre></p>
<b>工具的使用与效果


<p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;">    <span style="display: block;background: url("https://mmbiz.qpic.cn/mmbiz_svg/zZSYtpeVianTCibtUklhlFBD1Vsiabs2syn5mhW6hfq769uT1wnbSBTiaEsYnxhvPygrD7MHTb11oN7MeIiaXOTwicRWxmmCQ3pSm9/640?wx_fmt=svg") 10px 10px / 40px no-repeat rgb(250, 250, 250);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;"></span><code style="overflow-x: auto;padding: 16px;color: #383a42;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #fafafa;border-radius: 5px;">res = []<span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"去掉标题栏"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  /><span style="color: #a626a4;line-height: 26px;">if</span> json_content and <span style="color: #50a14f;line-height: 26px;">"中国"</span> <span style="color: #a626a4;line-height: 26px;">in</span> json_content[0][<span style="color: #50a14f;line-height: 26px;">"text"</span>]:<br  />    <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 中国联通行,去掉</span><br  />    x = json_content[0][<span style="color: #50a14f;line-height: 26px;">"position"</span>][0][0]<br  />    <span style="color: #a626a4;line-height: 26px;">for</span> i <span style="color: #a626a4;line-height: 26px;">in</span> range(1, len(json_content)):<br  />        <span style="color: #a626a4;line-height: 26px;">if</span> abs(json_content[<span style="color: #50a14f;line-height: 26px;">"position"</span>][0][0] - x) <= 20:<br  />            <span style="color: #c18401;line-height: 26px;">continue</span><br  />        <span style="color: #a626a4;line-height: 26px;">else</span>:<br  />            <span style="color: #c18401;line-height: 26px;">break</span><br  />    json_content = json_content[:i]<br  /><br  /><span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"去掉‘微信’"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  /><span style="color: #a626a4;line-height: 26px;">if</span> (<br  />    json_content<br  />    and <span style="color: #50a14f;line-height: 26px;">"微信"</span> <span style="color: #a626a4;line-height: 26px;">in</span> json_content[0][<span style="color: #50a14f;line-height: 26px;">"text"</span>]<br  />    and len(json_content[0][<span style="color: #50a14f;line-height: 26px;">"text"</span>]) < 8<br  />):<br  />    json_content = json_content[1:]<br  /><br  /><span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"首行是否为标题"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  /><span style="color: #a626a4;line-height: 26px;">if</span> not json_content:<br  />    <span style="color: #c18401;line-height: 26px;">return</span> res<br  />left_top_position = json_content[0][<span style="color: #50a14f;line-height: 26px;">"position"</span>][0]<br  />left_top_position_x = left_top_position[0]<br  />left_top_position_y = left_top_position[1]<br  /><span style="color: #a626a4;line-height: 26px;">if</span> left_top_position_y < 30 and len(json_content[0][<span style="color: #50a14f;line-height: 26px;">"text"</span>]) < 5:<br  />    <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 认为是标题</span><br  />    res.append({<span style="color: #50a14f;line-height: 26px;">"position"</span>: <span style="color: #50a14f;line-height: 26px;">"title"</span>, <span style="color: #50a14f;line-height: 26px;">"text"</span>: json_content[0][<span style="color: #50a14f;line-height: 26px;">"text"</span>]})<br  />    json_content = json_content[1:]<br  /><br  /><span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"同一句话判断的阈值"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  />same_sentence_threshold = 30<br  /><span style="color: #a626a4;line-height: 26px;">for</span> i <span style="color: #a626a4;line-height: 26px;">in</span> range(1, len(json_content)):<br  />    same_sentence_threshold = min(<br  />        same_sentence_threshold,<br  />        abs(<br  />            json_content[<span style="color: #50a14f;line-height: 26px;">"position"</span>][0][1]<br  />            - json_content[i - 1][<span style="color: #50a14f;line-height: 26px;">"position"</span>][0][1]<br  />        ),<br  />    )<br  />same_sentence_threshold = max(50, same_sentence_threshold + 35)  <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 误差</span><br  /><br  /><span style="color: #a626a4;line-height: 26px;">if</span> not json_content:<br  />    <span style="color: #c18401;line-height: 26px;">return</span> res<br  /><span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"找到左侧和右侧的位置"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  />left_around_position = min([i[<span style="color: #50a14f;line-height: 26px;">"position"</span>][0][0] <span style="color: #a626a4;line-height: 26px;">for</span> i <span style="color: #a626a4;line-height: 26px;">in</span> json_content])<br  />right_around_position = max([i[<span style="color: #50a14f;line-height: 26px;">"position"</span>][1][0] <span style="color: #a626a4;line-height: 26px;">for</span> i <span style="color: #a626a4;line-height: 26px;">in</span> json_content])<br  /><br  /><span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"判断左右"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  />n = len(json_content)<br  />text = <span style="color: #50a14f;line-height: 26px;">""</span><br  />position_left = 0<br  />position_right = 0<br  /><span style="color: #a626a4;line-height: 26px;">for</span> i <span style="color: #a626a4;line-height: 26px;">in</span> range(n):<br  />    <span style="color: #a626a4;line-height: 26px;">if</span> re.compile(r<span style="color: #50a14f;line-height: 26px;">"[0-9]{1,2}:[ ]{0,1}[0-9]{1,2}"</span>).findall(<br  />        json_content[<span style="color: #50a14f;line-height: 26px;">"text"</span>]<br  />    ):<br  />        <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 微信时间</span><br  />        <span style="color: #c18401;line-height: 26px;">continue</span><br  />    <span style="color: #a626a4;line-height: 26px;">if</span> <span style="color: #50a14f;line-height: 26px;">"微信"</span> <span style="color: #a626a4;line-height: 26px;">in</span> json_content[<span style="color: #50a14f;line-height: 26px;">"text"</span>]:<br  />        <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># ”微信“标题</span><br  />        <span style="color: #c18401;line-height: 26px;">continue</span><br  /><br  />    <span style="color: #a626a4;line-height: 26px;">if</span> (<br  />        i > 0<br  />        and abs(<br  />            json_content[<span style="color: #50a14f;line-height: 26px;">"position"</span>][0][1]<br  />            - json_content[i - 1][<span style="color: #50a14f;line-height: 26px;">"position"</span>][0][1]<br  />        )<br  />        < same_sentence_threshold<br  />    ):<br  />        <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 认为当前话跟上一句话是同一句话</span><br  />        text += json_content[<span style="color: #50a14f;line-height: 26px;">"text"</span>]<br  />    <span style="color: #a626a4;line-height: 26px;">else</span>:<br  />        <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 现在是另一个人说话,将上一个说的话保存</span><br  />        <span style="color: #a626a4;line-height: 26px;">if</span> text:<br  />            <span style="color: #a626a4;line-height: 26px;">if</span> res and res[-1][<span style="color: #50a14f;line-height: 26px;">"position"</span>] == <span style="color: #50a14f;line-height: 26px;">"left"</span>:<br  />                <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 如果上一句话是左边说的,我们更倾向于下一句话是右边的人说的</span><br  />                float_value = 25<br  />            <span style="color: #a626a4;line-height: 26px;">else</span>:<br  />                <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 否则,更倾向于左边的人说的</span><br  />                float_value = -5<br  />            <span style="color: #a626a4;line-height: 26px;">if</span> not res:<br  />                <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 第一句话更倾向于右边的人说的</span><br  />                float_value = 25<br  />            <span style="color: #a626a4;line-height: 26px;">if</span> abs(position_left - left_around_position) + float_value < abs(<br  />                position_right - right_around_position<br  />            ):<br  />                <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 离左侧更近</span><br  />                res.append({<span style="color: #50a14f;line-height: 26px;">"position"</span>: <span style="color: #50a14f;line-height: 26px;">"left"</span>, <span style="color: #50a14f;line-height: 26px;">"text"</span>: text})<br  />            <span style="color: #a626a4;line-height: 26px;">else</span>:<br  />                <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 离右侧更近</span><br  />                res.append({<span style="color: #50a14f;line-height: 26px;">"position"</span>: <span style="color: #50a14f;line-height: 26px;">"right"</span>, <span style="color: #50a14f;line-height: 26px;">"text"</span>: text})<br  />        text = json_content[<span style="color: #50a14f;line-height: 26px;">"text"</span>]<br  />        position_left = json_content[<span style="color: #50a14f;line-height: 26px;">"position"</span>][0][0]<br  />        position_right = json_content[<span style="color: #50a14f;line-height: 26px;">"position"</span>][1][0]<br  /><span style="color: #a626a4;line-height: 26px;">if</span> text:<br  />    <span style="color: #a626a4;line-height: 26px;">if</span> res and res[-1][<span style="color: #50a14f;line-height: 26px;">"position"</span>] == <span style="color: #50a14f;line-height: 26px;">"left"</span>:<br  />        <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 如果上一句话是左边说的,我们更倾向于下一句话是右边的人说的</span><br  />        float_value = 25<br  />    <span style="color: #a626a4;line-height: 26px;">else</span>:<br  />        <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 否则,更倾向于左边的人说的</span><br  />        float_value = -5<br  />    <span style="color: #a626a4;line-height: 26px;">if</span> not res:<br  />        <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 第一句话更倾向于右边的人说的</span><br  />        float_value = 25<br  />    <span style="color: #a626a4;line-height: 26px;">if</span> abs(position_left - left_around_position) + float_value < abs(<br  />        position_right - right_around_position<br  />    ):<br  />        <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 离左侧更近</span><br  />        res.append({<span style="color: #50a14f;line-height: 26px;">"position"</span>: <span style="color: #50a14f;line-height: 26px;">"left"</span>, <span style="color: #50a14f;line-height: 26px;">"text"</span>: text})<br  />    <span style="color: #a626a4;line-height: 26px;">else</span>:<br  />        <span style="color: #a0a1a7;font-style: italic;line-height: 26px;"># 离右侧更近</span><br  />        res.append({<span style="color: #50a14f;line-height: 26px;">"position"</span>: <span style="color: #50a14f;line-height: 26px;">"right"</span>, <span style="color: #50a14f;line-height: 26px;">"text"</span>: text})<br  /><span style="color: #a626a4;line-height: 26px;">if</span> len(res) == 1:<br  />    <span style="color: #c18401;line-height: 26px;">return</span> []<br  /><span style="color: #c18401;line-height: 26px;">return</span> res<br  /></code></pre></p>
借助这些简便的一键式生成工具,用户轻松打造高品质微信对话短视频。工具配备直观的操作界面,仅需输入对话脚本,选择相关图片资源,轻点生成按键,即可快速获得成品视频。简化的制作流程大幅降低了视频生产的难度,使得更多用户得以参与视频创作。



效果究竟能达至何种程度?用户反馈显示,借助这些工具制作的视频,播放量和收益均明显上涨。以某用户为例,其首部视频播放量仅为167次,而次视频播放量则激增至1.6万次。这一现象有力地证实了这些工具的实效性,并揭示了通过制作微信对话视频实现盈利的潜力。

<b>工具的普及与未来展望


一键生成工具的广泛应用促使众多用户跻身微信对话视频制作领域。这些工具不仅助力个人创作者,还为企业和品牌开辟了创新营销途径。利用创意对话视频,企业品牌可更高效吸引目标观众,增强品牌认知度和用户互动性。

展望未来,技术不断发展,将这些工具的功能提升至新的高度,并简化操作流程。预计微信对话视频制作将迈向智能化,甚至可能实现全自动化,从而允许创作者将更多资源专注于创意而非技术细节。

<p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;">    <span style="display: block;background: url("https://mmbiz.qpic.cn/mmbiz_svg/zZSYtpeVianTCibtUklhlFBD1Vsiabs2syn5mhW6hfq769uT1wnbSBTiaEsYnxhvPygrD7MHTb11oN7MeIiaXOTwicRWxmmCQ3pSm9/640?wx_fmt=svg") 10px 10px / 40px no-repeat rgb(250, 250, 250);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;"></span><code style="overflow-x: auto;padding: 16px;color: #383a42;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #fafafa;border-radius: 5px;">app = FastAPI()<br  />app.mount(<br  />    <span style="color: #50a14f;line-height: 26px;">"/static"</span>,<br  />    StaticFiles(directory=MAIN_PATH.joinpath(<span style="color: #50a14f;line-height: 26px;">"weixin_chat"</span>, <span style="color: #50a14f;line-height: 26px;">"static"</span>)),<br  />    name=<span style="color: #50a14f;line-height: 26px;">"static"</span>,<br  />)<br  /><br  />@app.route(<span style="color: #50a14f;line-height: 26px;">"/"</span>)<br  />def index(*args, **kwargs):<br  />    <span style="color: #c18401;line-height: 26px;">return</span> HTMLResponse(<br  />        MAIN_PATH.joinpath(<br  />            <span style="color: #50a14f;line-height: 26px;">"weixin_chat"</span>,<br  />            <span style="color: #50a14f;line-height: 26px;">"index.html"</span>,<br  />        ).read_text(encoding=<span style="color: #50a14f;line-height: 26px;">"utf-8"</span>)<br  />    )<br  /></code></pre></p>
<b>结语与互动


微信对话视频的流行,首要得益于其丰富且有趣的内容,更得益于支撑其背后的技术实力。随着一键生成工具的问世,制作此类视频的门槛大幅降低,促使更多人得以加入创作行列。您也想动手制作一款专属的微信对话视频吗?欢迎在评论区交流您的想法与经验,共同挖掘工具的潜力,创作出更加精彩的内容。

<p><pre data-tool="mdnice编辑器" style="margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;">    <span style="display: block;background: url("https://mmbiz.qpic.cn/mmbiz_svg/zZSYtpeVianTCibtUklhlFBD1Vsiabs2syn5mhW6hfq769uT1wnbSBTiaEsYnxhvPygrD7MHTb11oN7MeIiaXOTwicRWxmmCQ3pSm9/640?wx_fmt=svg") 10px 10px / 40px no-repeat rgb(250, 250, 250);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;"></span><code style="overflow-x: auto;padding: 16px;color: #383a42;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #fafafa;border-radius: 5px;">browser = playwright.chromium.launch(headless=True)<br  />context = browser.new_context()<br  /><br  />page = context.new_page()<br  />page.goto(<span style="color: #50a14f;line-height: 26px;">"http://127.0.0.1:36999"</span>)<br  />page.wait_for_load_state()<br  /><span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"生成标题"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  /><span style="color: #a626a4;line-height: 26px;">if</span> formatted_jsons[0][<span style="color: #50a14f;line-height: 26px;">"position"</span>] == <span style="color: #50a14f;line-height: 26px;">"title"</span>:<br  />    page.fill(title, formatted_jsons[0][<span style="color: #50a14f;line-height: 26px;">"text"</span>])<br  />    formatted_jsons = formatted_jsons[1:]<br  /><span style="color: #a626a4;line-height: 26px;">else</span>:<br  />    titles = [<span style="color: #50a14f;line-height: 26px;">"佳佳"</span>, <span style="color: #50a14f;line-height: 26px;">"小小"</span>, <span style="color: #50a14f;line-height: 26px;">"♥"</span>, <span style="color: #50a14f;line-height: 26px;">"❀"</span>, <span style="color: #50a14f;line-height: 26px;">"啊呜"</span>, <span style="color: #50a14f;line-height: 26px;">"奔波儿灞与灞波儿奔"</span>, <span style="color: #50a14f;line-height: 26px;">"亲亲"</span>]<br  />    page.fill(title, random.choice(titles))<br  />time.sleep(0.2)<br  /><span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"跳转到对话页"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  />page.click(<br  />    <span style="color: #50a14f;line-height: 26px;">"#vueApp > div > div.edit-content > div.tab > ul > li:nth-child(2) > a"</span><br  />)<br  />time.sleep(0.2)<br  />page.wait_for_selector(<br  />    <span style="color: #50a14f;line-height: 26px;">"#tabContent2 > div > div.dialog-user-items > div:nth-child(1) > div > a.dialog-user-face-a > input[type=file]"</span><br  />)<br  /><span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"清空对话"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  />page.on(<span style="color: #50a14f;line-height: 26px;">"dialog"</span>, lambda dialog: dialog.accept())<br  />page.click(clear_conv)<br  />time.sleep(0.2)<br  /><span style="color: #50a14f;line-height: 26px;">""</span><span style="color: #50a14f;line-height: 26px;">"选取头像"</span><span style="color: #50a14f;line-height: 26px;">""</span><br  />photos = self.two_random_photo()<br  />page.set_input_files(my_photo, photos[0])<br  />time.sleep(0.2)<br  />page.set_input_files(second_photo, photos[1])<br  />time.sleep(0.2)<br  />_uuid = <span style="color: #50a14f;line-height: 26px;">""</span>.join(<br  />    re.compile(r<span style="color: #50a14f;line-height: 26px;">"[0-9a-zA-Z\u4e00-\u9fa5]*"</span>).findall(<br  />        <span style="color: #50a14f;line-height: 26px;">""</span>.join(map(lambda e: e[<span style="color: #50a14f;line-height: 26px;">"text"</span>], formatted_jsons))<br  />    )<br  />)<br  />save_path = WORK_PATH.joinpath(self.keyword, <span style="color: #50a14f;line-height: 26px;">"images"</span>, _uuid[:15])<br  />save_path.mkdir(parents=True, exist_ok=True)<br  />index = 0<br  /><span style="color: #a626a4;line-height: 26px;">for</span> _json <span style="color: #a626a4;line-height: 26px;">in</span> formatted_jsons:<br  />    <span style="color: #a626a4;line-height: 26px;">if</span> _json[<span style="color: #50a14f;line-height: 26px;">"position"</span>] == <span style="color: #50a14f;line-height: 26px;">"left"</span>:<br  />        page.click(select_left)<br  />    <span style="color: #a626a4;line-height: 26px;">else</span>:<br  />        page.click(select_right)<br  />    time.sleep(0.2)<br  />    page.fill(input_words, _json[<span style="color: #50a14f;line-height: 26px;">"text"</span>])<br  />    page.click(add_words)<br  />    time.sleep(0.2)<br  />    save_file = save_path.joinpath(f<span style="color: #50a14f;line-height: 26px;">"{index}.jpg"</span>)<br  />    page.locator(target_area).screenshot(<br  />        path=save_file, quality=100, <span style="color: #c18401;line-height: 26px;">type</span>=<span style="color: #50a14f;line-height: 26px;">"jpeg"</span><br  />    )<br  />    index += 1<br  /></code></pre></p>
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则