Python自动读取剪贴板中的云盘链接地址与提取码并使用默认浏览器打开网页

查看 8|回复 0
作者:MowChan   
功能说明
使用正则表达式匹配百度网盘分享文本中的链接地址与提取码,拼接成自动填写提取码的URL,并用系统默认浏览器打开。
为了提高效率,使用 clipboard monitor 模块侦听系统剪贴板,如果满足正则表达式的匹配,则自动打开网页。
运行环境
  • Windows 7 及以上
  • Python 3.x

    源代码
    import re
    import webbrowser
    import clipboard_monitor
    def listen_text(text):
        regex = r"链接.*?https://pan.baidu.com(.*?)\s*提取码.*?([a-z0-9]{4})"
        matches = re.finditer(regex, text, re.MULTILINE)
        for matchNum, match in enumerate(matches):
            baidu_link = match.groups()
            if baidu_link:
                baidu_link_result = 'https://pan.baidu.com{}?pwd={}'.format(*baidu_link)
                print('\a')
                webbrowser.open(baidu_link_result, new=0, autoraise=True)
                print(baidu_link_result)
    clipboard_monitor.on_text(listen_text)
    clipboard_monitor.wait()

    剪贴板, 链接

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

    返回顶部