安装pyperclip模块
pyperclip 模块有 copy() 和 paste() 函数, 可以向计算机的剪贴板发送文本, 或从它接收文本。
pip install pyperclip
使用
pyperclip.paste() #当前剪贴板上的内容,从剪贴板接收文本
pyperclip.copy(‘Hello world!’) #复制文本到剪贴板,剪贴板的内容是:Hello world!
import pyperclip
import time
while True:
txt = pyperclip.paste().replace(' ','').replace(' ','')
# print(txt)
pyperclip.copy(txt)
time.sleep(0.5)
找出复制文本内容中的错别字
首先得要有个字库,建个文本存放着,导入到函数里查找就行了。
自动下载复制文本内容中的图片
有时候复制粘贴时,要下载图片,需要占右键下载,这下好了,直接复制地址就下载好了
import requests
import pyperclip
import time
while True:
nowtime = time.strftime("%m-%d", time.localtime())
txt=pyperclip.paste()
# print(len(txt),txt)
img_name_list = ['jpg','jpge','png']
imgurl = ''
for name in img_name_list:
if len(txt)<200 and txt.count(name) and txt.count('http'):
imgurl=txt[txt.find('http'):txt.find(name)+len(name)]
imgurl_1 = imgurl[-9:-len(name)-1]
print(imgurl)
if len(imgurl)>10:
request = requests.get(imgurl)
with open('C:\\Users\\Administrator\\Pictures\\{}-{}.jpg'.format(nowtime,imgurl_1), 'wb') as f:
f.write(request.content)
txt = pyperclip.paste().replace(' ','').replace(' ','')
pyperclip.copy(txt)
time.sleep(1)