代码如下:
from selenium import webdriverimport timebrowser = webdriver.Chrome(r'C:\Users\administrator\Desktop\chromedriver.exe')headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36', }browser.get('http://localhost:800/admin/List.aspx')def button(w): xx = browser.find_elements_by_CSS_selector('button') for i in xx: if w in i.text: print(w) i.click() break else: passdef text(): txt = open(r'C:\Users\administrator\Desktop\syfw\shiyefuwu\test.txt') txt = txt.read() txt = txt.split('\n') #print(txt) return txtdef tian(name): button('添加站点') browser.switch_to.frame(0) x=browser.find_element_by_ID('mc') x.send_keys(name) y=browser.find_element_by_ID('url') y.send_keys(name) z=browser.find_element_by_xpath('/HTML/body/div/div/form/div[5]/div/div[1]/i') z.click() browser.find_element_by_ID('button1').click() time.sleep(1) alert = browser.switch_to.alert #切到d出框 print(alert.text) a=alert.text alert.accept() #确定 return '添加成功!' in a def mian(): txt = text() while len(txt)!=0: time.sleep(1) name = txt[0] try: s = tian(name) if s: print(name+'成功!') txt.pop(0) else: pass except: print(name,end='') print('————出错5秒后重试') time.sleep(2) browser.refresh() time.sleep(3) mian()
总结
以上是内存溢出为你收集整理的使用Python完成自动录入信息全部内容,希望文章能够帮你解决使用Python完成自动录入信息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)