我已经打开了一个文本文件作为tf,我想从txt.file中删除例如文本“hello”,如何做这是最快的方法?我要删除的文本保存为“+”,列出了所有数字
import os
from tkinter import *
from tkinter import filedialog
import selenium
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium import webdriver
from selenium import webdriver
import contextlib as textmanager
PATH= "C:\Program Files (x86)\chromedrivers\chromedriver.exe"
driver= webdriver.Chrome(PATH)
list_of_numbers=[]
full_list_of_numbers_work=[]
在这里,我以tf的身份打开文件
def openFile():
tf = filedialog.askopenfilename(
initialdir="C:/Users/MainFrame/Desktop/",
title="Open Text file",
filetypes=(("Text Files", "*.txt"),)
)
pathh.insert(END, tf)
with open(tf) as f: # use context manager
for line in f:
txtarea.insert(END, line)
line = line.strip()
if line:
list_of_numbers.append(int(line))
ws = Tk()
ws.title("PythonGuides")
ws.geometry("400x450")
ws['bg']='#fb0'
txtarea = Text(ws, width=40, height=20)
txtarea.pack(pady=20)
pathh = Entry(ws)
pathh.pack(side=LEFT, expand=True, fill=X, padx=20)
Button(
ws,
text="Open File",
command=openFile
).pack(side=RIGHT, expand=True, fill=X, padx=20)
ws.mainloop()
driver.get("https://login.yahoo.com/?.lang=en-US&src=homepage&.done=https%3A%2F%2Fwww.yahoo.com%2F&pspid=2023538075&activity=ybar-signin")
input_field= driver.find_element_by_id("login-username")
button_for_next= driver.find_element_by_id("login-signin")
counting=0
这就是我想要从文件中删除文本的地方,我想要一种快速的方法
while counting !=len(list_of_numbers):
input_field.send_keys("+", list_of_numbers[counting])
button_for_next.click()
if len(driver.find_elements_by_css_selector("p[data-error]")) > 0:
#remove the item which is "+" , list_of_numbers[counting]
暂无答案!
目前还没有任何答案,快来回答吧!