python——操作剪贴板,删除文本中的空格

安装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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值