复制网址,粘贴带标题
作者:
陈成_Adam | 来源:发表于
2023-09-18 13:57 被阅读0次import clipboard
import requests
import re
def is_url(string):
url_pattern = re.compile(r'^(http|https)://[^\s/$.?#].[^\s]*$')
return bool(re.match(url_pattern, string))
if __name__ == '__main__':
if is_url(clipboard.paste()):
url = clipboard.paste()
response = requests.get(url)
title_matched = re.match(r'.*<title.*?>(.*?)</title>.*', response.text, re.DOTALL)
if title_matched:
title = title_matched.group(1).strip()
out_str = '%s[%s]' % (url, title)
print(out_str)
clipboard.copy(out_str)
else:
print('没有找到标题,网址是:%s' % url)
else:
print('复制的不是一个网址')
本文标题:复制网址,粘贴带标题
本文链接:https://www.haomeiwen.com/subject/dxwvvdtx.html
网友评论