自动转载其他网站的文章,管理员端口,selenium,pykeyboard,xlrd

from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from pykeyboard import PyKeyboard
from selenium.webdriver.support.ui import Select

import xlrd


wd = webdriver.Chrome(r'E:\chromedriver_win32\chromedriver.exe')

wd.implicitly_wait(10)

wd.get('http:ml')
element2=wd.find_element_by_class_name('una')#用户名
element2.send_keys('in')

element4=wd.find_element_by_name('passw')#用户名
element4.send_keys('')
time.sleep(2)
element=wd.find_element_by_name('verify')#验证码
element.click()
time.sleep(20)
element3=wd.find_element_by_class_name('btn-block')#登录
element3.click()

time.sleep(5)


element5=wd.find_element_by_class_name('fa-server')#点击政策发布

actions=ActionChains(wd)
actions.move_to_element(element5).click()


time.sleep(2)
element6=wd.find_element_by_css_selector('[href="/index.php/Admin/Policy/index"]')
actions.move_to_element(element6).click()
time.sleep(3)


actions.perform()

js='window.open("httpadd");'#新打开标签页
wd.execute_script(js)

# wd.switch_to.frame('iframe0')



handles = wd.window_handles # 获取当前窗口句柄集合(列表类型),切换窗口
wd.switch_to_window(handles[1])

elementsc=wd.find_element_by_css_selector('[href="javascript:void(0)"]')
elementsc.click()




time.sleep(5)
k=PyKeyboard()
imgdc=r'C:\Users\Administrator\Desktop\verify.png'
k.type_string(imgdc)
time.sleep(2)
k.press_key(k.alt_key)
k.tap_key('o')
k.release_key(k.alt_key)











excel = xlrd.open_workbook(r"C:\Users\Administrator\Desktop\kjt.xlsx")


sheet = excel.sheet_by_name(r'Sheet 1')
titlew=sheet.cell(1,1).value
contentw1=sheet.cell(1,2).value
contentw2=sheet.cell(1,3).value







elementw1=wd.find_element_by_css_selector('[style="width:60%;"]')
elementw1.send_keys(titlew)


select = Select(wd.find_element_by_css_selector('[name="cid"]'))
select.select_by_visible_text("科技类")

# elementw2=wd.find_element_by_css_selector('[id="myEditor"]')

# elementw2.send_keys(contentw1)
# elementw2.send_keys('\n')
# elementw2.send_keys(contentw2)
elementwh=wd.find_element_by_css_selector('[class="edui-icon-source edui-icon"]')
elementwh.click()


time.sleep(0.5)
elementw2=wd.find_element_by_css_selector('[style="resize: none; border: 0px; padding: 0px; margin: 0px; overflow-y: auto; outline: 0px; width: 820px; height: 240px;"]')
elementw2.send_keys(contentw1)
elementw2.send_keys('\n')
elementw2.send_keys(contentw2)
elementwh.click()







elementw3=wd.find_element_by_css_selector('[class="btn btn-primary"]')
elementw3.click()








# element7=wd.find_element_by_css_selector('a[href="javascript:;"][onclick="add_data()"]')
# element7.click()
# wd.get('http://lankao.palmble.com/index.php/Admin/Policy/index')

# wd.get('http://lankao.palmble.com/admin/policy/add')

# spans = element.find_elements_by_tag_name('li')
# for span in spans:
#     print(span.text)

 

上一篇:python常用模块:url.parse 模块


下一篇:【Appium遇到的坑】环境配置无误,提示error: Logcat capture failed: spawn ENOENT