爬虫+Qt5 抖音视频评论爬取

前言         

小菜鸟一枚,最近把学习结合在了一块,做了一个抖音评论采集,不能采集到二级评论,代码可能有些臃肿,主要是把抓取和数据保存到表格没做优化,还是复制的抓取的代码。还没写多线程,抓取几千上万的的评论可能需要等几分钟,有需求的朋友可以拿去用,也希望可以有大佬优化下代码。            

抖音ID是链接中的modal_id 后面的数字    
                                                                                    
    记得给我评分增加热心值哦!!!

环境准备
import math
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import os
import requests
import json
import time
from openpyxl import Workbook
数据默认存放到程序同目录下以下为代码实现:

import math
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import os
import requests
import json
import time
from openpyxl import Workbook
 
class QuestionMessageBox(QMessageBox):
    def __init__(self,parent,title,content):
        super().__init__(parent)
        self.setWindowTitle(title)
        self.setText(content)
        self.setIconPixmap(QPixmap('logo.png'))#消息框中间图标
 
class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.init_UI()
        self.cwd = os.getcwd()  # 获取当前程序文件位置
 
    def init_UI(self):
        self.resize(1000,800)
        self.setWindowTitle('抖音评论信息采集')
        self.setWindowIcon(QIcon("logo.png"))
 
        self.video_id = QLabel('输入视频ID:',self)
        self.video_edit = QLineEdit(self)
        self.video_run = QPushButton('查询')
        self.save_label = QLabel('保存路径:',self)
        self.save_edit = QLineEdit(self)
        self.save_path = QPushButton('选择路径')
        self.save_run = QPushButton('生成表格')
 
        self.model = QStandardItemModel()
        #横向标题
        self.model.setHorizontalHeaderLabels(['id','uid','抖音呢称','抖音号','主页地址','评论内容','评论时间','签名','IP地址'])
        #表格视图
        self.tableView = QTableView()
        #
        self.tableView.setModel(self.model)
        self.tableView.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)#所有列自动拉伸,充满界面
 
        v_layout =QVBoxLayout()
        h_layout1 = QHBoxLayout()
        h_layout1.addWidget(self.video_id)
        h_layout1.addWidget(self.video_edit)
        h_layout1.addWidget(self.video_run)
        h_layout2 = QHBoxLayout()
        h_layout2.addWidget(self.save_label)
        h_layout2.addWidget(self.save_edit)
        h_layout2.addWidget(self.save_path)
        h_layout2.addWidget(self.save_run)
 
        v_layout.addWidget(self.tableView)
        v_layout.addLayout(h_layout1)
        v_layout.addLayout(h_layout2)
 
        self.setLayout(v_layout)
 
        self.video_run.clicked.connect(self.query)
        self.save_path.clicked.connect(self.path)
        self.save_run.clicked.connect(self.save)
 
    def query(self):
        #获取抖音视频id
        dyid = self.video_edit.text()
        if len(str(dyid)) == 19:
            # 开始运行
            # ua = fake_useragent.UserAgent()
            url = f"https://www.douyin.com/aweme/v1/web/comment/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id={dyid}&cursor=0&count=50&item_type=0&rcFT=&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1280&screen_height=720&browser_language=zh-CN&browser_platform=Win32&browser_name=Edge&browser_version=110.0.1587.69&browser_online=true&engine_name=Blink&engine_version=110.0.0.0&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7209199745494419004&msToken=c06obL4RfLxVcgMOnHvmp0Rw6n1cWsV9uKVnX6ijf83fG0NgI91bDILO9kI2-9BmAPIGbGJW4UA6eJqxzzL8ZvFBwvZr4011Ggg30R--ciAVZNyr4VFHPB4rgtYsbzk=&X-Bogus=DFSzswVYgPkANjcZtabV85ppgizs"
            headers = {
                "cookie": "__live_version__=%221.1.1.3119%22; n_mh=LBW_csTRo4o17MRBoHN-WGE30EI-sJ-voBEni7jX2hk; store-region=cn-sx; store-region-src=uid; __security_server_data_status=1; my_rd=2; ttwid=1%7C4O9bPHcBAKpAoaYvl0Uv0pNnco7AX4wicVgjqtgo9WI%7C1695917171%7Cd09c1586edde72d96f0ab1e0fa3d0c8a3649fc0473187da76d85b8ca41de18d8; s_v_web_id=verify_ln7olkyk_pEQgeOxa_WX9u_4Pxo_9Fo3_hLFrr6xGV0mo; passport_csrf_token=747c8eded87cec59f5923aa141613d49; passport_csrf_token_default=747c8eded87cec59f5923aa141613d49; webcast_local_quality=null; strategyABtestKey=%221697880601.303%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.5%7D; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%2C%22isForcePopClose%22%3A1%7D; d_ticket=f93cc10db18537f6d95434b270dcdb902a4d1; download_guide=%223%2F20231021%2F0%22; sso_uid_tt=03b63ca8ce6e4973dfc44cc44beb25fb; sso_uid_tt_ss=03b63ca8ce6e4973dfc44cc44beb25fb; toutiao_sso_user=1e9393ec86e534188602763db6368684; toutiao_sso_user_ss=1e9393ec86e534188602763db6368684; passport_assist_user=CkExi2AeA8PD-ufXh4B-q229mhwPhMLTg-LKXckQ6whqAUbuGyonJZ4Mqf5zdlfmWY3yBjC86boBELI1PPHcK32CBRpKCjx1wvyNKsZZTEp8Ul8KpkWogcdbmD1e0wTp7uHpIeCDpjZ-HCCYR0s4wWTMtSUHZizMz-1XdGwHXRijkQMQ_Za_DRiJr9ZUIAEiAQMYLWF3; sid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; ssid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; odin_tt=38e56ec26b601cb7244cab424a4a3f283c30268c52d63b8d4fb64c89f096e9d43d1a3933fe9da4f47b8d85bf22e746353903f3219af9541341ea014df379f9d3; passport_auth_status=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; passport_auth_status_ss=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; uid_tt=f6989a34a0da04d37d6d1fe1a3998ad2; uid_tt_ss=f6989a34a0da04d37d6d1fe1a3998ad2; sid_tt=51a5f74e1321d2cd00622e6d57949da0; sessionid=51a5f74e1321d2cd00622e6d57949da0; sessionid_ss=51a5f74e1321d2cd00622e6d57949da0; publish_badge_show_info=%220%2C0%2C0%2C1697898547758%22; LOGIN_STATUS=1; _bd_ticket_crypt_doamin=2; _bd_ticket_crypt_cookie=d9f64365a44173a55d81fb97c293307a; sid_guard=51a5f74e1321d2cd00622e6d57949da0%7C1697898550%7C5183997%7CWed%2C+20-Dec-2023+14%3A29%3A07+GMT; sid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; ssid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; csrf_session_id=2e667b2ec9070962c1587cdf53864155; pwa2=%220%7C0%7C3%7C0%22; __ac_nonce=06533edb20087ff9f49be; __ac_signature=_02B4Z6wo00f01cSU.KQAAIDCkRZ3OYE8kqHEtPgAABQYtbLkom809HCf5hXtBNWnb4K3PcdJr4tCBET4Qyet0Vmc5d1qJCLDLsULVZj1Tb7Ad4NItn07DeEpVPYSTxMWzV4DdTFMtZHHQ7WM19; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1707%2C%5C%22screen_height%5C%22%3A1067%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A16%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A100%7D%22; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697903204183%22; douyin.com; device_web_cpu_core=16; device_web_memory_size=8; architecture=amd64; IsDouyinActive=true; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1698507142035%2C%22type%22%3A1%7D; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCRWNYQ05JMXlNNmdLVXFOSkFsOGRhN01lTmJvaFFSeGIvNXRjNUVETjg2SjJqU1hNSzJld1A5NnN1dnIxOHU3V29MUkg3aGZnWTV4TC9GSlVjUWZiejQ9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; passport_fe_beating_status=true; msToken=l5hyXj_B4wiV4OQ3UjhXdblrJEPUIZsm0g3PFdNbKznTQ8NJ5oZYg0jSzeJ16nX19WBjosXFzSJIe9FFRgK62LtKd8vBKH1PBparKkMhxccN5dfzlvnpeeGX0bc=; home_can_add_dy_2_desktop=%221%22; msToken=ppHb-TIKFSUraDPlw8idyszcPBENO5n-oAuAvKZE4lFafYRSdHR4Hqm0vuxArs4Z2nwHVK11sZZyuyZ5Z0zmnRDkTJikvY-yh8u2XZ4s6mTdoxRSUsmNip_CEh8=; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697902948392%22; tt_scid=eQpYz-Pmn9p3AhrGKETNlvhiT2A-IATD1Ek4XsTpsSaqjD-IDlkF3KUwnxS5l1TGc265",
                "referer": "https://www.douyin.com/video/7208081644471848247",
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0'
            }
            data = requests.get(url, headers=headers)
            result_list = json.loads(data.text)
            dy_total = result_list['total']  # 评论总数
 
            print(f"评论总数:{dy_total}")
 
            dy_total_num = dy_total / 50
            dy_num = math.ceil(dy_total_num)
            print(dy_num)
            cursor = 0
            row = 0
            dy_num_id = 1
            for i in range(dy_num):
                urls = f"https://www.douyin.com/aweme/v1/web/comment/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id={dyid}&cursor={cursor}&count=50&item_type=0&rcFT=&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1280&screen_height=720&browser_language=zh-CN&browser_platform=Win32&browser_name=Edge&browser_version=110.0.1587.69&browser_online=true&engine_name=Blink&engine_version=110.0.0.0&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7209199745494419004&msToken=c06obL4RfLxVcgMOnHvmp0Rw6n1cWsV9uKVnX6ijf83fG0NgI91bDILO9kI2-9BmAPIGbGJW4UA6eJqxzzL8ZvFBwvZr4011Ggg30R--ciAVZNyr4VFHPB4rgtYsbzk=&X-Bogus=DFSzswVYgPkANjcZtabV85ppgizs"
                headers = {
                    "cookie": "__live_version__=%221.1.1.3119%22; n_mh=LBW_csTRo4o17MRBoHN-WGE30EI-sJ-voBEni7jX2hk; store-region=cn-sx; store-region-src=uid; __security_server_data_status=1; my_rd=2; ttwid=1%7C4O9bPHcBAKpAoaYvl0Uv0pNnco7AX4wicVgjqtgo9WI%7C1695917171%7Cd09c1586edde72d96f0ab1e0fa3d0c8a3649fc0473187da76d85b8ca41de18d8; s_v_web_id=verify_ln7olkyk_pEQgeOxa_WX9u_4Pxo_9Fo3_hLFrr6xGV0mo; passport_csrf_token=747c8eded87cec59f5923aa141613d49; passport_csrf_token_default=747c8eded87cec59f5923aa141613d49; webcast_local_quality=null; strategyABtestKey=%221697880601.303%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.5%7D; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%2C%22isForcePopClose%22%3A1%7D; d_ticket=f93cc10db18537f6d95434b270dcdb902a4d1; download_guide=%223%2F20231021%2F0%22; sso_uid_tt=03b63ca8ce6e4973dfc44cc44beb25fb; sso_uid_tt_ss=03b63ca8ce6e4973dfc44cc44beb25fb; toutiao_sso_user=1e9393ec86e534188602763db6368684; toutiao_sso_user_ss=1e9393ec86e534188602763db6368684; passport_assist_user=CkExi2AeA8PD-ufXh4B-q229mhwPhMLTg-LKXckQ6whqAUbuGyonJZ4Mqf5zdlfmWY3yBjC86boBELI1PPHcK32CBRpKCjx1wvyNKsZZTEp8Ul8KpkWogcdbmD1e0wTp7uHpIeCDpjZ-HCCYR0s4wWTMtSUHZizMz-1XdGwHXRijkQMQ_Za_DRiJr9ZUIAEiAQMYLWF3; sid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; ssid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; odin_tt=38e56ec26b601cb7244cab424a4a3f283c30268c52d63b8d4fb64c89f096e9d43d1a3933fe9da4f47b8d85bf22e746353903f3219af9541341ea014df379f9d3; passport_auth_status=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; passport_auth_status_ss=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; uid_tt=f6989a34a0da04d37d6d1fe1a3998ad2; uid_tt_ss=f6989a34a0da04d37d6d1fe1a3998ad2; sid_tt=51a5f74e1321d2cd00622e6d57949da0; sessionid=51a5f74e1321d2cd00622e6d57949da0; sessionid_ss=51a5f74e1321d2cd00622e6d57949da0; publish_badge_show_info=%220%2C0%2C0%2C1697898547758%22; LOGIN_STATUS=1; _bd_ticket_crypt_doamin=2; _bd_ticket_crypt_cookie=d9f64365a44173a55d81fb97c293307a; sid_guard=51a5f74e1321d2cd00622e6d57949da0%7C1697898550%7C5183997%7CWed%2C+20-Dec-2023+14%3A29%3A07+GMT; sid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; ssid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; csrf_session_id=2e667b2ec9070962c1587cdf53864155; pwa2=%220%7C0%7C3%7C0%22; __ac_nonce=06533edb20087ff9f49be; __ac_signature=_02B4Z6wo00f01cSU.KQAAIDCkRZ3OYE8kqHEtPgAABQYtbLkom809HCf5hXtBNWnb4K3PcdJr4tCBET4Qyet0Vmc5d1qJCLDLsULVZj1Tb7Ad4NItn07DeEpVPYSTxMWzV4DdTFMtZHHQ7WM19; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1707%2C%5C%22screen_height%5C%22%3A1067%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A16%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A100%7D%22; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697903204183%22; douyin.com; device_web_cpu_core=16; device_web_memory_size=8; architecture=amd64; IsDouyinActive=true; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1698507142035%2C%22type%22%3A1%7D; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCRWNYQ05JMXlNNmdLVXFOSkFsOGRhN01lTmJvaFFSeGIvNXRjNUVETjg2SjJqU1hNSzJld1A5NnN1dnIxOHU3V29MUkg3aGZnWTV4TC9GSlVjUWZiejQ9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; passport_fe_beating_status=true; msToken=l5hyXj_B4wiV4OQ3UjhXdblrJEPUIZsm0g3PFdNbKznTQ8NJ5oZYg0jSzeJ16nX19WBjosXFzSJIe9FFRgK62LtKd8vBKH1PBparKkMhxccN5dfzlvnpeeGX0bc=; home_can_add_dy_2_desktop=%221%22; msToken=ppHb-TIKFSUraDPlw8idyszcPBENO5n-oAuAvKZE4lFafYRSdHR4Hqm0vuxArs4Z2nwHVK11sZZyuyZ5Z0zmnRDkTJikvY-yh8u2XZ4s6mTdoxRSUsmNip_CEh8=; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697902948392%22; tt_scid=eQpYz-Pmn9p3AhrGKETNlvhiT2A-IATD1Ek4XsTpsSaqjD-IDlkF3KUwnxS5l1TGc265",
                    "referer": "https://www.douyin.com/video/7208081644471848247",
                    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0'
                }
                print(urls)
                # print(urls)
                data = requests.get(urls, headers=headers)
                result_list = json.loads(data.text)
                result = result_list["comments"]
                # print(result)
                for dy in result:
                    dy_text = dy['text']  # 文本
                    dy_time = dy['create_time']  # 评论时间
                    dy_time1 = time.localtime(dy_time)  # 时间转换元组
                    dy_time2 = time.strftime("%Y-%m-%d %H:%M:%S", dy_time1)  # 时间戳转换为时间
                    dy_uid = dy['user']['uid']  # 用户uid
                    dy_short_id = dy['user']['short_id']  # 用户ID
                    dy_username = dy['user']['nickname']  # 用户名
                    dy_signature = dy['user']['signature']  # 用户签名
                    dy_ip_label = dy['ip_label']  # IP地址
                    dy_sec_uid = dy['user']['sec_uid']  # 主页地址
                    # print(dy_uid, dy_short_id, dy_username, dy_text, dy_signature, dy_time2)
                    column = 0
                    # 只显示字符串  不显示Int类型
                    self.model.setItem(row, column, QStandardItem(str(dy_num_id)))
                    column += 1
                    self.model.setItem(row, column, QStandardItem(dy_uid))
                    column += 1
                    self.model.setItem(row, column, QStandardItem(dy_username))
                    column += 1
                    self.model.setItem(row, column, QStandardItem(dy_short_id))
                    column += 1
                    self.model.setItem(row, column, QStandardItem("https://www.douyin.com/user/" + dy_sec_uid))
                    column += 1
                    self.model.setItem(row, column, QStandardItem(dy_text))
                    column += 1
                    self.model.setItem(row, column, QStandardItem(dy_time2))
                    column += 1
                    self.model.setItem(row, column, QStandardItem(dy_signature))
                    column += 1
                    self.model.setItem(row, column, QStandardItem(dy_ip_label))
                    column += 1
                    row += 1
                    dy_num_id += 1
                cursor += 20
            return
        else:
            choice = QuestionMessageBox(self, '错误', '视频ID不正确!')
            choice.exec()  # 显示一个模式对话框,并且锁住程序直到用户关闭该对话框为止。函数返回一个DialogCode结果。在对话框弹出期间,用户不可以切换同程序下的其它窗口,直到该对话框被关闭。
            return
        #开始运行
        #ua = fake_useragent.UserAgent()
        url = f"https://www.douyin.com/aweme/v1/web/comment/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id={dyid}&cursor=0&count=50&item_type=0&rcFT=&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1280&screen_height=720&browser_language=zh-CN&browser_platform=Win32&browser_name=Edge&browser_version=110.0.1587.69&browser_online=true&engine_name=Blink&engine_version=110.0.0.0&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7209199745494419004&msToken=c06obL4RfLxVcgMOnHvmp0Rw6n1cWsV9uKVnX6ijf83fG0NgI91bDILO9kI2-9BmAPIGbGJW4UA6eJqxzzL8ZvFBwvZr4011Ggg30R--ciAVZNyr4VFHPB4rgtYsbzk=&X-Bogus=DFSzswVYgPkANjcZtabV85ppgizs"
        headers = {
            "cookie": "__live_version__=%221.1.1.3119%22; n_mh=LBW_csTRo4o17MRBoHN-WGE30EI-sJ-voBEni7jX2hk; store-region=cn-sx; store-region-src=uid; __security_server_data_status=1; my_rd=2; ttwid=1%7C4O9bPHcBAKpAoaYvl0Uv0pNnco7AX4wicVgjqtgo9WI%7C1695917171%7Cd09c1586edde72d96f0ab1e0fa3d0c8a3649fc0473187da76d85b8ca41de18d8; s_v_web_id=verify_ln7olkyk_pEQgeOxa_WX9u_4Pxo_9Fo3_hLFrr6xGV0mo; passport_csrf_token=747c8eded87cec59f5923aa141613d49; passport_csrf_token_default=747c8eded87cec59f5923aa141613d49; webcast_local_quality=null; strategyABtestKey=%221697880601.303%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.5%7D; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%2C%22isForcePopClose%22%3A1%7D; d_ticket=f93cc10db18537f6d95434b270dcdb902a4d1; download_guide=%223%2F20231021%2F0%22; sso_uid_tt=03b63ca8ce6e4973dfc44cc44beb25fb; sso_uid_tt_ss=03b63ca8ce6e4973dfc44cc44beb25fb; toutiao_sso_user=1e9393ec86e534188602763db6368684; toutiao_sso_user_ss=1e9393ec86e534188602763db6368684; passport_assist_user=CkExi2AeA8PD-ufXh4B-q229mhwPhMLTg-LKXckQ6whqAUbuGyonJZ4Mqf5zdlfmWY3yBjC86boBELI1PPHcK32CBRpKCjx1wvyNKsZZTEp8Ul8KpkWogcdbmD1e0wTp7uHpIeCDpjZ-HCCYR0s4wWTMtSUHZizMz-1XdGwHXRijkQMQ_Za_DRiJr9ZUIAEiAQMYLWF3; sid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; ssid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; odin_tt=38e56ec26b601cb7244cab424a4a3f283c30268c52d63b8d4fb64c89f096e9d43d1a3933fe9da4f47b8d85bf22e746353903f3219af9541341ea014df379f9d3; passport_auth_status=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; passport_auth_status_ss=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; uid_tt=f6989a34a0da04d37d6d1fe1a3998ad2; uid_tt_ss=f6989a34a0da04d37d6d1fe1a3998ad2; sid_tt=51a5f74e1321d2cd00622e6d57949da0; sessionid=51a5f74e1321d2cd00622e6d57949da0; sessionid_ss=51a5f74e1321d2cd00622e6d57949da0; publish_badge_show_info=%220%2C0%2C0%2C1697898547758%22; LOGIN_STATUS=1; _bd_ticket_crypt_doamin=2; _bd_ticket_crypt_cookie=d9f64365a44173a55d81fb97c293307a; sid_guard=51a5f74e1321d2cd00622e6d57949da0%7C1697898550%7C5183997%7CWed%2C+20-Dec-2023+14%3A29%3A07+GMT; sid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; ssid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; csrf_session_id=2e667b2ec9070962c1587cdf53864155; pwa2=%220%7C0%7C3%7C0%22; __ac_nonce=06533edb20087ff9f49be; __ac_signature=_02B4Z6wo00f01cSU.KQAAIDCkRZ3OYE8kqHEtPgAABQYtbLkom809HCf5hXtBNWnb4K3PcdJr4tCBET4Qyet0Vmc5d1qJCLDLsULVZj1Tb7Ad4NItn07DeEpVPYSTxMWzV4DdTFMtZHHQ7WM19; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1707%2C%5C%22screen_height%5C%22%3A1067%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A16%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A100%7D%22; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697903204183%22; douyin.com; device_web_cpu_core=16; device_web_memory_size=8; architecture=amd64; IsDouyinActive=true; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1698507142035%2C%22type%22%3A1%7D; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCRWNYQ05JMXlNNmdLVXFOSkFsOGRhN01lTmJvaFFSeGIvNXRjNUVETjg2SjJqU1hNSzJld1A5NnN1dnIxOHU3V29MUkg3aGZnWTV4TC9GSlVjUWZiejQ9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; passport_fe_beating_status=true; msToken=l5hyXj_B4wiV4OQ3UjhXdblrJEPUIZsm0g3PFdNbKznTQ8NJ5oZYg0jSzeJ16nX19WBjosXFzSJIe9FFRgK62LtKd8vBKH1PBparKkMhxccN5dfzlvnpeeGX0bc=; home_can_add_dy_2_desktop=%221%22; msToken=ppHb-TIKFSUraDPlw8idyszcPBENO5n-oAuAvKZE4lFafYRSdHR4Hqm0vuxArs4Z2nwHVK11sZZyuyZ5Z0zmnRDkTJikvY-yh8u2XZ4s6mTdoxRSUsmNip_CEh8=; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697902948392%22; tt_scid=eQpYz-Pmn9p3AhrGKETNlvhiT2A-IATD1Ek4XsTpsSaqjD-IDlkF3KUwnxS5l1TGc265",
            "referer": "https://www.douyin.com/video/7208081644471848247",
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0'
        }
        data = requests.get(url, headers=headers)
        result_list = json.loads(data.text)
        dy_total = result_list['total']  # 评论总数
 
        print(f"评论总数:{dy_total}")
 
        dy_total_num = dy_total / 50
        dy_num = math.ceil(dy_total_num)
        print(dy_num)
        cursor = 0
        row = 0
        dy_num_id = 1
        for i in range(dy_num):
            urls = f"https://www.douyin.com/aweme/v1/web/comment/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id={dyid}&cursor={cursor}&count=50&item_type=0&rcFT=&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1280&screen_height=720&browser_language=zh-CN&browser_platform=Win32&browser_name=Edge&browser_version=110.0.1587.69&browser_online=true&engine_name=Blink&engine_version=110.0.0.0&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7209199745494419004&msToken=c06obL4RfLxVcgMOnHvmp0Rw6n1cWsV9uKVnX6ijf83fG0NgI91bDILO9kI2-9BmAPIGbGJW4UA6eJqxzzL8ZvFBwvZr4011Ggg30R--ciAVZNyr4VFHPB4rgtYsbzk=&X-Bogus=DFSzswVYgPkANjcZtabV85ppgizs"
            headers = {
                "cookie": "__live_version__=%221.1.1.3119%22; n_mh=LBW_csTRo4o17MRBoHN-WGE30EI-sJ-voBEni7jX2hk; store-region=cn-sx; store-region-src=uid; __security_server_data_status=1; my_rd=2; ttwid=1%7C4O9bPHcBAKpAoaYvl0Uv0pNnco7AX4wicVgjqtgo9WI%7C1695917171%7Cd09c1586edde72d96f0ab1e0fa3d0c8a3649fc0473187da76d85b8ca41de18d8; s_v_web_id=verify_ln7olkyk_pEQgeOxa_WX9u_4Pxo_9Fo3_hLFrr6xGV0mo; passport_csrf_token=747c8eded87cec59f5923aa141613d49; passport_csrf_token_default=747c8eded87cec59f5923aa141613d49; webcast_local_quality=null; strategyABtestKey=%221697880601.303%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.5%7D; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%2C%22isForcePopClose%22%3A1%7D; d_ticket=f93cc10db18537f6d95434b270dcdb902a4d1; download_guide=%223%2F20231021%2F0%22; sso_uid_tt=03b63ca8ce6e4973dfc44cc44beb25fb; sso_uid_tt_ss=03b63ca8ce6e4973dfc44cc44beb25fb; toutiao_sso_user=1e9393ec86e534188602763db6368684; toutiao_sso_user_ss=1e9393ec86e534188602763db6368684; passport_assist_user=CkExi2AeA8PD-ufXh4B-q229mhwPhMLTg-LKXckQ6whqAUbuGyonJZ4Mqf5zdlfmWY3yBjC86boBELI1PPHcK32CBRpKCjx1wvyNKsZZTEp8Ul8KpkWogcdbmD1e0wTp7uHpIeCDpjZ-HCCYR0s4wWTMtSUHZizMz-1XdGwHXRijkQMQ_Za_DRiJr9ZUIAEiAQMYLWF3; sid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; ssid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; odin_tt=38e56ec26b601cb7244cab424a4a3f283c30268c52d63b8d4fb64c89f096e9d43d1a3933fe9da4f47b8d85bf22e746353903f3219af9541341ea014df379f9d3; passport_auth_status=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; passport_auth_status_ss=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; uid_tt=f6989a34a0da04d37d6d1fe1a3998ad2; uid_tt_ss=f6989a34a0da04d37d6d1fe1a3998ad2; sid_tt=51a5f74e1321d2cd00622e6d57949da0; sessionid=51a5f74e1321d2cd00622e6d57949da0; sessionid_ss=51a5f74e1321d2cd00622e6d57949da0; publish_badge_show_info=%220%2C0%2C0%2C1697898547758%22; LOGIN_STATUS=1; _bd_ticket_crypt_doamin=2; _bd_ticket_crypt_cookie=d9f64365a44173a55d81fb97c293307a; sid_guard=51a5f74e1321d2cd00622e6d57949da0%7C1697898550%7C5183997%7CWed%2C+20-Dec-2023+14%3A29%3A07+GMT; sid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; ssid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; csrf_session_id=2e667b2ec9070962c1587cdf53864155; pwa2=%220%7C0%7C3%7C0%22; __ac_nonce=06533edb20087ff9f49be; __ac_signature=_02B4Z6wo00f01cSU.KQAAIDCkRZ3OYE8kqHEtPgAABQYtbLkom809HCf5hXtBNWnb4K3PcdJr4tCBET4Qyet0Vmc5d1qJCLDLsULVZj1Tb7Ad4NItn07DeEpVPYSTxMWzV4DdTFMtZHHQ7WM19; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1707%2C%5C%22screen_height%5C%22%3A1067%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A16%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A100%7D%22; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697903204183%22; douyin.com; device_web_cpu_core=16; device_web_memory_size=8; architecture=amd64; IsDouyinActive=true; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1698507142035%2C%22type%22%3A1%7D; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCRWNYQ05JMXlNNmdLVXFOSkFsOGRhN01lTmJvaFFSeGIvNXRjNUVETjg2SjJqU1hNSzJld1A5NnN1dnIxOHU3V29MUkg3aGZnWTV4TC9GSlVjUWZiejQ9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; passport_fe_beating_status=true; msToken=l5hyXj_B4wiV4OQ3UjhXdblrJEPUIZsm0g3PFdNbKznTQ8NJ5oZYg0jSzeJ16nX19WBjosXFzSJIe9FFRgK62LtKd8vBKH1PBparKkMhxccN5dfzlvnpeeGX0bc=; home_can_add_dy_2_desktop=%221%22; msToken=ppHb-TIKFSUraDPlw8idyszcPBENO5n-oAuAvKZE4lFafYRSdHR4Hqm0vuxArs4Z2nwHVK11sZZyuyZ5Z0zmnRDkTJikvY-yh8u2XZ4s6mTdoxRSUsmNip_CEh8=; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697902948392%22; tt_scid=eQpYz-Pmn9p3AhrGKETNlvhiT2A-IATD1Ek4XsTpsSaqjD-IDlkF3KUwnxS5l1TGc265",
                "referer": "https://www.douyin.com/video/7208081644471848247",
                'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0'
            }
            print(urls)
            #print(urls)
            data = requests.get(urls, headers=headers)
            result_list = json.loads(data.text)
            result = result_list["comments"]
            # print(result)
            for dy in result:
                dy_text = dy['text'] # 文本
                dy_time = dy['create_time'] # 评论时间
                dy_time1 = time.localtime(dy_time) # 时间转换元组
                dy_time2 = time.strftime("%Y-%m-%d %H:%M:%S", dy_time1)  # 时间戳转换为时间
                dy_uid = dy['user']['uid']  # 用户uid
                dy_short_id = dy['user']['short_id'] # 用户ID
                dy_username = dy['user']['nickname']  # 用户名
                dy_signature = dy['user']['signature'] # 用户签名
                dy_ip_label = dy['ip_label']  # IP地址
                dy_sec_uid = dy['user']['sec_uid']  # 主页地址
                #print(dy_uid, dy_short_id, dy_username, dy_text, dy_signature, dy_time2)
                column = 0
                #只显示字符串  不显示Int类型
                self.model.setItem(row, column, QStandardItem(str(dy_num_id)))
                column +=1
                self.model.setItem(row, column, QStandardItem(dy_uid))
                column += 1
                self.model.setItem(row, column, QStandardItem(dy_username))
                column += 1
                self.model.setItem(row, column, QStandardItem(dy_short_id))
                column += 1
                self.model.setItem(row, column, QStandardItem("https://www.douyin.com/user/"+dy_sec_uid))
                column += 1
                self.model.setItem(row, column, QStandardItem(dy_text))
                column += 1
                self.model.setItem(row, column, QStandardItem(dy_time2))
                column += 1
                self.model.setItem(row, column, QStandardItem(dy_signature))
                column += 1
                self.model.setItem(row, column, QStandardItem(dy_ip_label))
                column += 1
                row +=1
                dy_num_id+=1
                time.sleep(2)
            cursor += 20
 
    def path(self):
        #文件对话框
        dir_path = QFileDialog.getExistingDirectory(self,"选取文件夹",self.cwd)
        if dir_path == "":
            print("\n取消选择")
            return
        self.save_edit.setText(dir_path)
        #print("你选择的文件夹是:"+dir_path)
 
    def save(self):
        # 获取抖音视频id
        dyid = self.video_edit.text()
        dy_path = self.save_edit.text()
        # 开始运行
        url = f"https://www.douyin.com/aweme/v1/web/comment/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id={dyid}&cursor=0&count=50&item_type=0&rcFT=&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1280&screen_height=720&browser_language=zh-CN&browser_platform=Win32&browser_name=Edge&browser_version=110.0.1587.69&browser_online=true&engine_name=Blink&engine_version=110.0.0.0&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7209199745494419004&msToken=c06obL4RfLxVcgMOnHvmp0Rw6n1cWsV9uKVnX6ijf83fG0NgI91bDILO9kI2-9BmAPIGbGJW4UA6eJqxzzL8ZvFBwvZr4011Ggg30R--ciAVZNyr4VFHPB4rgtYsbzk=&X-Bogus=DFSzswVYgPkANjcZtabV85ppgizs"
        headers = {
            "cookie": "__live_version__=%221.1.1.3119%22; n_mh=LBW_csTRo4o17MRBoHN-WGE30EI-sJ-voBEni7jX2hk; store-region=cn-sx; store-region-src=uid; __security_server_data_status=1; my_rd=2; ttwid=1%7C4O9bPHcBAKpAoaYvl0Uv0pNnco7AX4wicVgjqtgo9WI%7C1695917171%7Cd09c1586edde72d96f0ab1e0fa3d0c8a3649fc0473187da76d85b8ca41de18d8; s_v_web_id=verify_ln7olkyk_pEQgeOxa_WX9u_4Pxo_9Fo3_hLFrr6xGV0mo; passport_csrf_token=747c8eded87cec59f5923aa141613d49; passport_csrf_token_default=747c8eded87cec59f5923aa141613d49; webcast_local_quality=null; strategyABtestKey=%221697880601.303%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.5%7D; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%2C%22isForcePopClose%22%3A1%7D; d_ticket=f93cc10db18537f6d95434b270dcdb902a4d1; download_guide=%223%2F20231021%2F0%22; sso_uid_tt=03b63ca8ce6e4973dfc44cc44beb25fb; sso_uid_tt_ss=03b63ca8ce6e4973dfc44cc44beb25fb; toutiao_sso_user=1e9393ec86e534188602763db6368684; toutiao_sso_user_ss=1e9393ec86e534188602763db6368684; passport_assist_user=CkExi2AeA8PD-ufXh4B-q229mhwPhMLTg-LKXckQ6whqAUbuGyonJZ4Mqf5zdlfmWY3yBjC86boBELI1PPHcK32CBRpKCjx1wvyNKsZZTEp8Ul8KpkWogcdbmD1e0wTp7uHpIeCDpjZ-HCCYR0s4wWTMtSUHZizMz-1XdGwHXRijkQMQ_Za_DRiJr9ZUIAEiAQMYLWF3; sid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; ssid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; odin_tt=38e56ec26b601cb7244cab424a4a3f283c30268c52d63b8d4fb64c89f096e9d43d1a3933fe9da4f47b8d85bf22e746353903f3219af9541341ea014df379f9d3; passport_auth_status=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; passport_auth_status_ss=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; uid_tt=f6989a34a0da04d37d6d1fe1a3998ad2; uid_tt_ss=f6989a34a0da04d37d6d1fe1a3998ad2; sid_tt=51a5f74e1321d2cd00622e6d57949da0; sessionid=51a5f74e1321d2cd00622e6d57949da0; sessionid_ss=51a5f74e1321d2cd00622e6d57949da0; publish_badge_show_info=%220%2C0%2C0%2C1697898547758%22; LOGIN_STATUS=1; _bd_ticket_crypt_doamin=2; _bd_ticket_crypt_cookie=d9f64365a44173a55d81fb97c293307a; sid_guard=51a5f74e1321d2cd00622e6d57949da0%7C1697898550%7C5183997%7CWed%2C+20-Dec-2023+14%3A29%3A07+GMT; sid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; ssid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; csrf_session_id=2e667b2ec9070962c1587cdf53864155; pwa2=%220%7C0%7C3%7C0%22; __ac_nonce=06533edb20087ff9f49be; __ac_signature=_02B4Z6wo00f01cSU.KQAAIDCkRZ3OYE8kqHEtPgAABQYtbLkom809HCf5hXtBNWnb4K3PcdJr4tCBET4Qyet0Vmc5d1qJCLDLsULVZj1Tb7Ad4NItn07DeEpVPYSTxMWzV4DdTFMtZHHQ7WM19; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1707%2C%5C%22screen_height%5C%22%3A1067%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A16%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A100%7D%22; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697903204183%22; douyin.com; device_web_cpu_core=16; device_web_memory_size=8; architecture=amd64; IsDouyinActive=true; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1698507142035%2C%22type%22%3A1%7D; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCRWNYQ05JMXlNNmdLVXFOSkFsOGRhN01lTmJvaFFSeGIvNXRjNUVETjg2SjJqU1hNSzJld1A5NnN1dnIxOHU3V29MUkg3aGZnWTV4TC9GSlVjUWZiejQ9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; passport_fe_beating_status=true; msToken=l5hyXj_B4wiV4OQ3UjhXdblrJEPUIZsm0g3PFdNbKznTQ8NJ5oZYg0jSzeJ16nX19WBjosXFzSJIe9FFRgK62LtKd8vBKH1PBparKkMhxccN5dfzlvnpeeGX0bc=; home_can_add_dy_2_desktop=%221%22; msToken=ppHb-TIKFSUraDPlw8idyszcPBENO5n-oAuAvKZE4lFafYRSdHR4Hqm0vuxArs4Z2nwHVK11sZZyuyZ5Z0zmnRDkTJikvY-yh8u2XZ4s6mTdoxRSUsmNip_CEh8=; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697902948392%22; tt_scid=eQpYz-Pmn9p3AhrGKETNlvhiT2A-IATD1Ek4XsTpsSaqjD-IDlkF3KUwnxS5l1TGc265",
            "referer": "https://www.douyin.com/video/7208081644471848247",
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0'
        }
        data = requests.get(url, headers=headers)
        result_list = json.loads(data.text)
        dy_total = result_list['total']  # 评论总数
        # 创建excel
        wb = Workbook()
        ws1 = wb.create_sheet('抖音', 0)
        ws1.append(['id', 'uid', '抖音昵称', '抖音号', '主页地址', '评论内容', '评论时间', '签名', 'IP地址'])
        excel_id = 1
 
        dy_total_num = dy_total / 50
        dy_num = math.ceil(dy_total_num)
        cursor = 0
        # print(round(2))
        for i in range(dy_num):
            urls = f"https://www.douyin.com/aweme/v1/web/comment/list/?device_platform=webapp&aid=6383&channel=channel_pc_web&aweme_id={dyid}&cursor={cursor}&count=50&item_type=0&rcFT=&pc_client_type=1&version_code=170400&version_name=17.4.0&cookie_enabled=true&screen_width=1280&screen_height=720&browser_language=zh-CN&browser_platform=Win32&browser_name=Edge&browser_version=110.0.1587.69&browser_online=true&engine_name=Blink&engine_version=110.0.0.0&os_name=Windows&os_version=10&cpu_core_num=8&device_memory=8&platform=PC&downlink=10&effective_type=4g&round_trip_time=50&webid=7209199745494419004&msToken=c06obL4RfLxVcgMOnHvmp0Rw6n1cWsV9uKVnX6ijf83fG0NgI91bDILO9kI2-9BmAPIGbGJW4UA6eJqxzzL8ZvFBwvZr4011Ggg30R--ciAVZNyr4VFHPB4rgtYsbzk=&X-Bogus=DFSzswVYgPkANjcZtabV85ppgizs"
            headers = {
                "cookie": "__live_version__=%221.1.1.3119%22; n_mh=LBW_csTRo4o17MRBoHN-WGE30EI-sJ-voBEni7jX2hk; store-region=cn-sx; store-region-src=uid; __security_server_data_status=1; my_rd=2; ttwid=1%7C4O9bPHcBAKpAoaYvl0Uv0pNnco7AX4wicVgjqtgo9WI%7C1695917171%7Cd09c1586edde72d96f0ab1e0fa3d0c8a3649fc0473187da76d85b8ca41de18d8; s_v_web_id=verify_ln7olkyk_pEQgeOxa_WX9u_4Pxo_9Fo3_hLFrr6xGV0mo; passport_csrf_token=747c8eded87cec59f5923aa141613d49; passport_csrf_token_default=747c8eded87cec59f5923aa141613d49; webcast_local_quality=null; strategyABtestKey=%221697880601.303%22; volume_info=%7B%22isUserMute%22%3Afalse%2C%22isMute%22%3Afalse%2C%22volume%22%3A0.5%7D; FORCE_LOGIN=%7B%22videoConsumedRemainSeconds%22%3A180%2C%22isForcePopClose%22%3A1%7D; d_ticket=f93cc10db18537f6d95434b270dcdb902a4d1; download_guide=%223%2F20231021%2F0%22; sso_uid_tt=03b63ca8ce6e4973dfc44cc44beb25fb; sso_uid_tt_ss=03b63ca8ce6e4973dfc44cc44beb25fb; toutiao_sso_user=1e9393ec86e534188602763db6368684; toutiao_sso_user_ss=1e9393ec86e534188602763db6368684; passport_assist_user=CkExi2AeA8PD-ufXh4B-q229mhwPhMLTg-LKXckQ6whqAUbuGyonJZ4Mqf5zdlfmWY3yBjC86boBELI1PPHcK32CBRpKCjx1wvyNKsZZTEp8Ul8KpkWogcdbmD1e0wTp7uHpIeCDpjZ-HCCYR0s4wWTMtSUHZizMz-1XdGwHXRijkQMQ_Za_DRiJr9ZUIAEiAQMYLWF3; sid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; ssid_ucp_sso_v1=1.0.0-KGM5NTAyZTk3ZTk5NWJkZDRkMTczNTgyMTcyZmJiNGQ5ODVlNzg3MTMKHwjzh6C0x830AhCwwM-pBhjvMSAMMPTRnaYGOAZA9AcaAmxxIiAxZTkzOTNlYzg2ZTUzNDE4ODYwMjc2M2RiNjM2ODY4NA; odin_tt=38e56ec26b601cb7244cab424a4a3f283c30268c52d63b8d4fb64c89f096e9d43d1a3933fe9da4f47b8d85bf22e746353903f3219af9541341ea014df379f9d3; passport_auth_status=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; passport_auth_status_ss=5bafa0b8893ec64f4af7bbe64a7aebb0%2C; uid_tt=f6989a34a0da04d37d6d1fe1a3998ad2; uid_tt_ss=f6989a34a0da04d37d6d1fe1a3998ad2; sid_tt=51a5f74e1321d2cd00622e6d57949da0; sessionid=51a5f74e1321d2cd00622e6d57949da0; sessionid_ss=51a5f74e1321d2cd00622e6d57949da0; publish_badge_show_info=%220%2C0%2C0%2C1697898547758%22; LOGIN_STATUS=1; _bd_ticket_crypt_doamin=2; _bd_ticket_crypt_cookie=d9f64365a44173a55d81fb97c293307a; sid_guard=51a5f74e1321d2cd00622e6d57949da0%7C1697898550%7C5183997%7CWed%2C+20-Dec-2023+14%3A29%3A07+GMT; sid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; ssid_ucp_v1=1.0.0-KDVmNjVmMjA0YzMyNzY0MzgyY2ZkYTM4NGFmMGQzMjNmYjYwYTU3MzQKGwjzh6C0x830AhC2wM-pBhjvMSAMOAZA9AdIBBoCaGwiIDUxYTVmNzRlMTMyMWQyY2QwMDYyMmU2ZDU3OTQ5ZGEw; csrf_session_id=2e667b2ec9070962c1587cdf53864155; pwa2=%220%7C0%7C3%7C0%22; __ac_nonce=06533edb20087ff9f49be; __ac_signature=_02B4Z6wo00f01cSU.KQAAIDCkRZ3OYE8kqHEtPgAABQYtbLkom809HCf5hXtBNWnb4K3PcdJr4tCBET4Qyet0Vmc5d1qJCLDLsULVZj1Tb7Ad4NItn07DeEpVPYSTxMWzV4DdTFMtZHHQ7WM19; stream_recommend_feed_params=%22%7B%5C%22cookie_enabled%5C%22%3Atrue%2C%5C%22screen_width%5C%22%3A1707%2C%5C%22screen_height%5C%22%3A1067%2C%5C%22browser_online%5C%22%3Atrue%2C%5C%22cpu_core_num%5C%22%3A16%2C%5C%22device_memory%5C%22%3A8%2C%5C%22downlink%5C%22%3A10%2C%5C%22effective_type%5C%22%3A%5C%224g%5C%22%2C%5C%22round_trip_time%5C%22%3A100%7D%22; FOLLOW_NUMBER_YELLOW_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697903204183%22; douyin.com; device_web_cpu_core=16; device_web_memory_size=8; architecture=amd64; IsDouyinActive=true; VIDEO_FILTER_MEMO_SELECT=%7B%22expireTime%22%3A1698507142035%2C%22type%22%3A1%7D; bd_ticket_guard_client_data=eyJiZC10aWNrZXQtZ3VhcmQtdmVyc2lvbiI6MiwiYmQtdGlja2V0LWd1YXJkLWl0ZXJhdGlvbi12ZXJzaW9uIjoxLCJiZC10aWNrZXQtZ3VhcmQtcmVlLXB1YmxpYy1rZXkiOiJCRWNYQ05JMXlNNmdLVXFOSkFsOGRhN01lTmJvaFFSeGIvNXRjNUVETjg2SjJqU1hNSzJld1A5NnN1dnIxOHU3V29MUkg3aGZnWTV4TC9GSlVjUWZiejQ9IiwiYmQtdGlja2V0LWd1YXJkLXdlYi12ZXJzaW9uIjoxfQ%3D%3D; passport_fe_beating_status=true; msToken=l5hyXj_B4wiV4OQ3UjhXdblrJEPUIZsm0g3PFdNbKznTQ8NJ5oZYg0jSzeJ16nX19WBjosXFzSJIe9FFRgK62LtKd8vBKH1PBparKkMhxccN5dfzlvnpeeGX0bc=; home_can_add_dy_2_desktop=%221%22; msToken=ppHb-TIKFSUraDPlw8idyszcPBENO5n-oAuAvKZE4lFafYRSdHR4Hqm0vuxArs4Z2nwHVK11sZZyuyZ5Z0zmnRDkTJikvY-yh8u2XZ4s6mTdoxRSUsmNip_CEh8=; FOLLOW_LIVE_POINT_INFO=%22MS4wLjABAAAAiA0kXTMImfuv4fIhPFoZThKiKW5GMbpH9zj69URgFiM-X-a3OiAdtTUaK_Cmvsxt%2F1697904000000%2F0%2F0%2F1697902948392%22; tt_scid=eQpYz-Pmn9p3AhrGKETNlvhiT2A-IATD1Ek4XsTpsSaqjD-IDlkF3KUwnxS5l1TGc265",
                "referer": "https://www.douyin.com/video/7208081644471848247",
                'User-Agent':'Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0'
            }
            data = requests.get(urls, headers=headers)
            result_list = json.loads(data.text)
            result = result_list["comments"]
            for dy in result:
                dy_text = dy['text']  # 文本
                dy_time = dy['create_time']  # 评论时间
                dy_time1 = time.localtime(dy_time)  # 时间转换元组
                dy_time2 = time.strftime("%Y-%m-%d %H:%M:%S", dy_time1)  # 时间戳转换为时间
                dy_uid = dy['user']['uid']  # 用户uid
                dy_short_id = dy['user']['short_id']  # 用户ID
                dy_username = dy['user']['nickname']  # 用户名
                dy_signature = dy['user']['signature']  # 用户签名
                dy_ip_label = dy['ip_label']  # IP地址
                dy_sec_uid = dy['user']['sec_uid']  # 主页地址
                # print(dy_uid,dy_short_id,dy_username,dy_text,dy_signature,dy_time2)
                ws1.append(
                    [excel_id, dy_uid, dy_username, dy_short_id, "https://www.douyin.com/user/" + dy_sec_uid, dy_text,
                     dy_time2, dy_signature, dy_ip_label])
                excel_id += 1
            cursor += 20
        wb.save(f"{dy_path}/抖音{dyid}.xlsx")
        #消息框icon会跟着QIcon变化 self.setIconPixmap(QPixmap('logo.png'))#消息框中间图标
        choice = QuestionMessageBox(self, '信息框', '已保存')
        choice.exec()
 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = Window()
    w.show()
    app.exec_()

扫码免费获取资源: