11
This commit is contained in:
136
main.py
136
main.py
@ -16,105 +16,7 @@ from ftp import set_proxy
|
||||
from ftp import upload_file_to_ftp
|
||||
from ftp import upload_directory_to_ftp
|
||||
from ftp import create_remote_directory
|
||||
#
|
||||
# def ftp_upload_with_proxy(server, username, password, local_file_path, remote_path, proxy):
|
||||
# """使用 pycurl 上传单个文件到 FTP 服务器"""
|
||||
# buffer = BytesIO()
|
||||
# c = pycurl.Curl()
|
||||
#
|
||||
# # 设置 FTP URL
|
||||
# ftp_url = f'ftp://{server}/{remote_path}'
|
||||
# c.setopt(c.URL, ftp_url)
|
||||
#
|
||||
# # 设置 FTP 认证
|
||||
# c.setopt(c.USERPWD, f"{username}:{password}")
|
||||
# c.setopt(c.READDATA, open(local_file_path, 'rb'))
|
||||
# c.setopt(c.UPLOAD, 1)
|
||||
# c.setopt(c.PREQUOTE, ['PASV'])
|
||||
#
|
||||
# # 设置代理
|
||||
# c.setopt(c.PROXY, proxy)
|
||||
#
|
||||
# try:
|
||||
# c.perform()
|
||||
# print(f"文件 {local_file_path} 成功上传到 {remote_path}!")
|
||||
# except pycurl.error as e:
|
||||
# print(f"FTP 错误: {e}")
|
||||
# finally:
|
||||
# c.close()
|
||||
|
||||
# def upload_directory_to_ftp(server, username, password, local_directory, remote_directory, proxy):
|
||||
# """上传整个目录及其子目录到FTP服务器"""
|
||||
# # 确保远程目录存在
|
||||
# try:
|
||||
# # 此段代码需要检查并创建远程目录
|
||||
# # pycurl 不直接提供创建目录的功能,需要手动实现
|
||||
#
|
||||
# # 上传文件和子目录
|
||||
# for root, dirs, files in os.walk(local_directory):
|
||||
# # 上传子文件夹
|
||||
# for dir_name in dirs:
|
||||
# remote_dir_path = os.path.join(remote_directory,
|
||||
# os.path.relpath(os.path.join(root, dir_name), local_directory)).replace(
|
||||
# "\\", "/")
|
||||
# print(f"准备上传目录: {remote_dir_path}")
|
||||
# # 假设已确认远程目录存在
|
||||
#
|
||||
# # 上传文件
|
||||
# for filename in files:
|
||||
# local_file_path = os.path.join(root, filename) # 本地文件的完整路径
|
||||
# relative_path = os.path.relpath(local_file_path, local_directory) # 计算相对路径
|
||||
# remote_file_path = os.path.join(remote_directory, relative_path).replace("\\", "/") # 计算远程文件路径
|
||||
#
|
||||
# # 上传文件
|
||||
# ftp_upload_with_proxy(server, username, password, local_file_path, remote_file_path, proxy)
|
||||
#
|
||||
# except Exception as e:
|
||||
# print(f"上传目录时发生错误: {e}")
|
||||
#
|
||||
# def upload_file_to_ftp(server, username, password, file_path, remote_path):
|
||||
# try:
|
||||
# with ftplib.FTP(server) as ftp:
|
||||
# ftp.login(user=username, passwd=password)
|
||||
# with open(file_path, 'rb') as file:
|
||||
# ftp.storbinary(f'STOR {remote_path}', file)
|
||||
# print(f"文件 {file_path} 成功上传到 {remote_path}!")
|
||||
# except ftplib.all_errors as e:
|
||||
# print(f"FTP 错误: {e}")
|
||||
#
|
||||
# def upload_directory_to_ftp(server, username, password, local_directory, remote_directory):
|
||||
# """上传整个目录及其子目录到FTP服务器"""
|
||||
# try:
|
||||
# with ftplib.FTP(server) as ftp:
|
||||
# ftp.login(user=username, passwd=password)
|
||||
#
|
||||
# # 确保远程目录存在
|
||||
# try:
|
||||
# ftp.cwd(remote_directory) # 改变到远程目录
|
||||
# except ftplib.error_perm:
|
||||
# ftp.mkd(remote_directory) # 如果远程目录不存在,则创建
|
||||
# ftp.cwd(remote_directory) # 再次进入远程目录
|
||||
#
|
||||
# # 遍历本地目录树
|
||||
# for root, dirs, files in os.walk(local_directory):
|
||||
# # 上传子文件夹
|
||||
# for dir_name in dirs:
|
||||
# remote_dir_path = os.path.join(remote_directory, os.path.relpath(os.path.join(root, dir_name), local_directory)).replace("\\", "/")
|
||||
# try:
|
||||
# ftp.mkd(remote_dir_path) # 在FTP服务器上创建子目录
|
||||
# print(f"已创建远程目录: {remote_dir_path}")
|
||||
# except ftplib.error_perm:
|
||||
# pass # 如果目录已经存在则忽略
|
||||
#
|
||||
# # 上传文件
|
||||
# for filename in files:
|
||||
# local_file_path = os.path.join(root, filename) # 本地文件的完整路径
|
||||
# relative_path = os.path.relpath(local_file_path, local_directory) # 计算相对路径
|
||||
# remote_file_path = os.path.join(remote_directory, relative_path).replace("\\", "/") # 计算远程文件路径
|
||||
# upload_file_to_ftp(server, username, password, local_file_path, remote_file_path, ) # 上传文件
|
||||
#
|
||||
# except ftplib.all_errors as e:
|
||||
# print(f"上传目录时发生错误: {e}")
|
||||
|
||||
def launch_proxy():
|
||||
print("开启代理...")
|
||||
@ -227,41 +129,13 @@ def shot(chromedriver_path ,chrome_path):
|
||||
ftp_username = matches[2]
|
||||
ftp_password = matches[3]
|
||||
# 调用上传函数
|
||||
upload_directory_to_ftp(ftp_server, ftp_username, ftp_password, local_file_path, remote_file_path)
|
||||
upload_directory_to_ftp(ftp_server, ftp_username, ftp_password, local_file_path, remote_file_path, proxy_url)
|
||||
|
||||
# url = f"http://{matches[0]}:{matches[1]}/exam_setup.php"
|
||||
# response = requests.get(url, cookies=session_cookies)
|
||||
# print(response.raise_for_status())
|
||||
# print(response.text)
|
||||
time.sleep(5)
|
||||
driver.get(f"http://{matches[0]}:{matches[1]}/setup.html")
|
||||
|
||||
# 等待页面加载完成
|
||||
# WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "kw")))
|
||||
# 输入搜索词
|
||||
try:
|
||||
button = WebDriverWait(driver, 10).until(
|
||||
EC.element_to_be_clickable((By.XPATH, "//button[text()='create table']")) # 使用按钮的文本查找元素
|
||||
)
|
||||
button.click() # 点击按钮
|
||||
except Exception as e:
|
||||
print(f"发生错误: {e}")
|
||||
finally:
|
||||
result_content = ""
|
||||
try:
|
||||
result_element = WebDriverWait(driver, 100).until(
|
||||
EC.presence_of_element_located((By.ID, "result"))
|
||||
)
|
||||
|
||||
# 获取内容
|
||||
result_content = result_element.text
|
||||
print(f"ID为result的内容: {result_content}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"发生错误: {e}")
|
||||
|
||||
print("执行完毕:" + result_content)
|
||||
|
||||
|
||||
driver.get("http://125.64.9.222:8022/paper/paper.php")
|
||||
|
||||
@ -269,7 +143,7 @@ def shot(chromedriver_path ,chrome_path):
|
||||
wait = WebDriverWait(driver, 30)
|
||||
for fillingQ_id in fillingQ_ids:
|
||||
textarea = wait.until(EC.presence_of_element_located((By.ID, fillingQ_id)))
|
||||
with open (fillingQ_path + f"/{fillingQ_id}.txt", "r", encoding="utf-8") as f:
|
||||
with open (fillingQ_path + f"/{fillingQ_id}", "r", encoding="utf-8") as f:
|
||||
textarea.send_keys(f.read()) # 填写题目
|
||||
|
||||
for save in fillingQ_save_ids:
|
||||
@ -311,6 +185,7 @@ if __name__ == "__main__":
|
||||
|
||||
root = tk.Tk()
|
||||
root.title("一键执行")
|
||||
|
||||
|
||||
# 设置窗口大小
|
||||
window_width = 300
|
||||
@ -354,6 +229,5 @@ if __name__ == "__main__":
|
||||
submit_button.pack(side=tk.BOTTOM)
|
||||
submit_button.config(width=10, height=1)
|
||||
|
||||
|
||||
|
||||
root.mainloop()
|
||||
root.mainloop()
|
||||
close_proxy()
|
Reference in New Issue
Block a user