Commit d0fac8c2 by wangfa

Merge remote-tracking branch 'origin/master'

parents 0c6fc21c 44dda936
File deleted
......@@ -6,6 +6,8 @@
/dist
/build
/__pycache__
/.DS_Store
*.spec
*.zip
......
......@@ -317,6 +317,7 @@ class ToWork:
st += f' {item}'
change_prompt = st + ' ' + change_prompt
logger.info(change_prompt)
# 一个一个输入
await self.driver_paste(page, change_prompt)
# 回车
await page.keyboard.press('Enter')
......@@ -348,7 +349,14 @@ class ToWork:
st += f' {item}'
change_prompt = st + ' ' + change_prompt
logger.info(change_prompt)
# 一个一个输入
await self.driver_paste(page, change_prompt)
# 往元素里插入文本
# element
await page.evaluate('''(element) => {
element.innerHTML = '111'
}''', '')
# 回车
await page.keyboard.press('Enter')
await asyncio.sleep(2)
......
# 获取浏览器窗口
async def browser(self, browser_id):
"""
:return:
"""
self.browser_id = browser_id
ws = await self.bit_get_ws()
return await pyppeteer.connect({
"browserWSEndpoint": ws
})
# 图像质量增强
# client_id 为官网获取的AK, client_secret 为官网获取的SK
import requests
import base64
from loguru import logger
class ImgEnhance:
def __init__(self):
self.host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=SEVtEVlQPyqf55mgGt5u5Ad2&client_secret=0CNGhjMrgXRPmDE014S2IXyHLKCuTcfK'
self.res_token = ''
# 获取百度api的token
def get_api_token(self):
response = requests.get(self.host)
if response:
print(response.json())
access_token = response.json()['access_token']
self.res_token = access_token
print(access_token)
self.Work()
# self.Img_enlarge()
# 开始图片增强处理
def Work(self):
'''
图像清晰度增强
'''
request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/image_definition_enhance"
# 二进制方式打开图片文件
f = open('./res_assets/test_10.jpg', 'rb')
img = base64.b64encode(f.read())
params = {"image": img}
request_url = request_url + "?access_token=" + self.res_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
imgdata = base64.b64decode(response.json()["image"])
file = open(r'./res_assets/test_10.jpg', 'wb')
file.write(imgdata)
file.close()
# 图片无损放大
def Img_enlarge(self):
'''
图片无损放大
'''
request_url = "https://aip.baidubce.com/rest/2.0/image-process/v1/image_quality_enhance"
# 二进制方式打开图片文件
f = open('./res_assets/test_10.jpg', 'rb')
img = base64.b64encode(f.read())
params = {"image": img}
request_url = request_url + "?access_token=" + self.res_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
imgdata = base64.b64decode(response.json()["image"])
file = open(r'./res_assets/test_10.jpg', 'wb')
file.write(imgdata)
file.close()
if __name__ == '__main__':
Img = ImgEnhance()
Img.get_api_token()
import cv2
import os
import pathlib
target_path = "./res_assets"
def mkdir(path):
path = path.strip()
path = path.rstrip("\\")
isExists = os.path.exists(path)
if not isExists:
os.makedirs(path)
print(path + ' 创建成功')
return True
else:
print(path + ' 目录已存在')
return False
def split_img(img_file):
img = cv2.imread(img_file)
# 这一段是改为灰色
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_h = img.shape[0] # 高度
img_w = img.shape[1] # 宽度
# h1_half = int(img_h / 2)
# w1_half = int(img_w / 2)
h1_half = img_h // 2
w1_half = img_w // 2
img_name = os.path.basename(img_file)
for i in range(4):
img1 = img[int(i / 2) * h1_half: h1_half * (int(i / 2) + 1), int(i % 2) * w1_half: (int(i % 2) + 1) * w1_half]
img1_path = os.path.join(target_path, f"{img_name[:-4]}_{i}.jpg")
print("spilt img:", img1_path)
cv2.imwrite(img1_path, img1)
if __name__ == '__main__':
mkdir(target_path)
split_img(os.path.join('./assets', 'test.png'))
import socket
import requests
import json
task = {
'type': 1,
'prompt_img': json.dumps(['1111111'])
}
prompt_img = task['prompt_img']
if task['type'] == 1 and prompt_img and len(json.loads(prompt_img)):
print('可以执行')
import asyncio
import time
import pyppeteer
from loguru import logger
# 找元素,只找一次,不等待
async def FindElement(custom_el, path, el_type=''):
try:
el = (await custom_el.xpath(path))
if el_type == 'last':
return el[len(el) - 1]
else:
return el[0]
except Exception as e:
return False
# 登录
async def login(page):
time.sleep(30)
print('开始登录')
user_name_path = '//input[@name="email"]'
element = await FindElement(page, user_name_path)
logger.info(element)
async def main():
# 新窗口
browser = await pyppeteer.launch(options={
# 启用路径
'executablePath': r'F:\Software\chrome-py\chrome-win\chrome.exe',
'headless': False,
}, args=['–disable-infobars',
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
])
cur_pages = await browser.pages()
page = cur_pages[0]
await page.goto('https://discord.com/channels/@me')
await login(page)
# 测试文字
test_title = '你好你好你好222'
# 插入文本
input_path = '//*[@id="app-mount"]/div[2]/div[1]/div[1]/div/div[2]/div/div/div/div/div[2]/div/main/form/div/div[2]/div/div[2]/div/div/div/span[2]/span[2]/span/span/span'
element = await FindElement(page, input_path)
if element:
await page.evaluate('''(element,test_title) => {
element.innerHTML = test_title
}''', element, test_title)
logger.info('成功')
# 回车
await page.keyboard.press('Enter')
else:
logger.info('元素不存在')
time.sleep(1000)
asyncio.get_event_loop().run_until_complete(main())
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment