python 下载腾讯在线文档

import requests

"""
1. 手动到chrome获取下载请求
2. 获取excel的动态id
3. 拼出excel的下载链接
4. 下载
"""


class Excel:
    def __init__(self):
        self.cookie_string = ""
        self.headers = {
            "authority": "docs.qq.com",
            "method": "GET",
            "path": "/v1/export/query_progress?u=28b403f5c49b4e38add0acaff339ed41&operationId=144115215919843666_fb7bbca6-a03a-23df-f662-ffdbc961bb9f",
            "scheme": "https",
            "Accept": "application/json, text/plain, */*",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cookie": self.cookie_string,
            "Referer": "https://docs.qq.com/sheet/DU3NaS1h3Z2Voc09u?u=28b403f5c49b4e38add0acaff339ed41&tab=BB08J2",
            "Sec-Ch-Ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
            "Sec-Ch-Ua-Mobile": "?0",
            "Sec-Ch-Ua-Platform": "Windows",
            "Sec-Fetch-Dest": "empty",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Site": "same-origin",
            "Traceparent": "00-b895d4ff7358b61546dde0bd9c69e4fa-3d91d815d6e57d83-01",
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
        }

        self.data = {
            'exportType': 0,
            'switches': '{"embedFonts":false}',
            'exportSource': 'client',
            'docId': '300000000$SsZKXwgehsOn'
        }

    def get_operationId(self, browser_url):
        """
        :param browser_url: 浏览器的url
        :return: excel的动态id
        """
        "https://docs.qq.com/v1/export/export_office?u=28b403f5c49b4e38add0acaff339ed41"
        _response = requests.post(browser_url, data=self.data, headers=self.headers).json()
        print("excel动态id:", _response['operationId'])
        return _response['operationId']

    def excel_url(self, url):
        """
        获取excel的下载链接
        :return:
        """
        for i in range(5):
            response = requests.get(url, headers=self.headers).json()
            try:
                if response['file_url']:
                    return response['file_url']
            except Exception as e:
                pass
            else:
                return response['file_url']

    def write2excel(self, file_url, file_name="download_excel.xlsx"):
        """
        :param file_url: excel的下载链接
        :param file_name: excel命名
        :return:
        """
        excel_content = requests.get(url=file_url).content
        with open(file_name, 'wb') as f:
            f.write(excel_content)
        print("excel下载完成")

    # def split_url(self, browser_url):
    #     """
    #     分割url
    #     :param browser_url: 浏览器上的url
    #     :return:
    #     """
    #     return browser_url.split("&tab")[0]

    def __call__(self):
        """
        browser_url: chrome F12的下载请求:export_office
        :return:
        """
        # todo:通过浏览器url获取下载请求链接,解决需要f12的问题

        browser_url = ""
        operationId = self.get_operationId(browser_url)
        url = "https://docs.qq.com/v1/export/query_progress?u=28b403f5c49b4e38add0acaff339ed41&operationId=" + operationId
        excel_url = self.excel_url(url)
        self.write2excel(excel_url, file_name="download_excel.xlsx")


if __name__ == '__main__':
    debug = Excel()
    debug()

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Python可以使用第三方库来实现腾讯会议回放下载。目前比较流行的有两个库:Selenium和Requests。在这个回答中,我将介绍使用Selenium库来实现腾讯会议回放下载的方法。 首先,你需要安装Selenium库。你可以使用`pip`命令来安装它: ``` pip install selenium ``` 接下来,你需要下载Chrome浏览器驱动程序,以便Selenium可以控制浏览器。你可以通过这个链接下载:https://sites.google.com/a/chromium.org/chromedriver/downloads。请确保你下载的驱动程序版本与你的Chrome浏览器版本相匹配。 下载完成后,你需要将驱动程序移动到一个PATH环境变量指定的文件夹中,这样Selenium就可以找到它。 下面是一个使用Python实现腾讯会议回放下载的示例代码: ```python from selenium import webdriver import time # 创建一个浏览器对象,指定驱动程序的路径 driver = webdriver.Chrome('path/to/chromedriver') # 打开腾讯会议回放页面 driver.get('https://xxxxxx') # 填写需要的登录信息 # ... # 假设回放页面已经加载完成,等待一段时间以确保页面中的所有元素都加载完毕 time.sleep(5) # 找到回放下载按钮并点击 download_button = driver.find_element_by_xpath('//button[@class="download-btn"]') download_button.click() # 确认下载 confirm_button = driver.find_element_by_xpath('//button[@class="confirm-btn"]') confirm_button.click() # 等待下载完成,可以根据文件大小或下载时间进行控制 time.sleep(60) # 关闭浏览器 driver.quit() ``` 这个示例代码打开了腾讯会议回放页面,并模拟点击下载按钮,确认下载后等待60秒,然后关闭浏览器。 你可以根据需要修改代码来适应实际情况,比如填写登录信息、调整等待时间等。 需要注意的是,由于腾讯会议回放页面会不断更新,所以上述代码可能会由于页面结构和元素布局的变化而无法正常工作。在实际使用时,你可能需要根据新版本的页面进行相应的调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值