使用正则表达式匹配百度网盘分享文本中的链接地址与提取码,拼接成自动填写提取码的URL,并用系统默认浏览器打开。
为了提高效率,使用 clipboard monitor 模块侦听系统剪贴板,如果满足正则表达式的匹配,则自动打开网页。
运行环境
源代码
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()