1 Star 0 Fork 0

prcool/双随机系统

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
1打开页面.py 4.14 KB
一键复制 编辑 原始数据 按行查看 历史
prcool 提交于 2021-12-22 18:39 +08:00 . 11
from module import *
from selenium import webdriver
import logging, re
from lxml import etree
# # 加启动配置
# option = webdriver.ChromeOptions()
# # 关闭“chrome正受到自动测试软件的控制”
# option.add_experimental_option('useAutomationExtension', False)
# option.add_experimental_option('excludeSwitches', ['enable-automation'])
# # 不自动关闭浏览器
# option.add_experimental_option("detach", True)
# driver 必须写在全局函数中,如果写在局部函数内,调用函数执行完毕后,函数内的变量自动清除,
# 浏览器会关闭
#加启动配置
option = webdriver.ChromeOptions()
option.add_experimental_option('w3c', False)
option.add_experimental_option('useAutomationExtension', False)
option.add_experimental_option('excludeSwitches', ['enable-automation'])
#不自动关闭浏览器
option.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=option)
def first_open(url):
open_web(driver, url)
elements = find_element(driver)
action_login_nocode(driver, elements)
action_login_code(driver, elements)
n = 1
while 1:
time.sleep(1)
try:
driver.implicitly_wait(1) # 隐式等待10秒
record = driver.find_element_by_class_name('recordItem')
print('登录成功')
break
except:
n += 1
print(f'登录失败,第{n}次重试...')
code = input('请输入验证码:')
action_login(driver, elements, code)
if n > 5:
print('重试超过5次,登录失败,请手动输入。。。')
# input('waiting..')
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, '.recordItem')))
def get_info(driver):
# print('hello')
html = driver.find_element_by_xpath("//*").get_attribute("outerHTML")
with open('1.html', 'w', encoding='utf-8') as fp:
fp.write(html)
# 不要用 driver.page_source,那样得到的页面源码不标准
titles = re.findall(r'<div.*?class="van-cell__value"><span.*?>(.*?)</span></div>', html, re.DOTALL)
print(titles)
name = titles[0]
manager = titles[3]
phone = titles[4]
print(name, manager, phone)
# logging.info(titles)
def go_detail(driver):
# 点击检查按钮
tabItems = driver.find_elements_by_xpath("//li[@class='tab-item']")
check = tabItems[1]
check.click()
time.sleep(1)
# 获取tab菜单项
uncheck = driver.find_elements_by_xpath('//span[@class="van-ellipsis"]')
# 单击第一项
uncheck[0].click()
# 获取搜索栏
input_tag = driver.find_element_by_xpath('//input[@class="van-field__control"]')
# 单击搜索栏
input_tag.click()
# 清空搜索栏
input_tag.clear()
print('已清空文字')
# 输入新文字
input_tag.send_keys('hello2')
time.sleep(1)
# print(uncheck[1].get_attribute('outerHTML'))
# 点击tab第二项,未检查
uncheck[1].click()
time.sleep(1)
# 获取tab详情列表项(第一项为主页,为未检查单位列表,第二项为已检查未录入单位列表)
item = driver.find_elements_by_xpath('//div[@class="van-list"]')
print(item[1].get_attribute('outerHTML'))
# 单击第二项,第一个已检查但未录入的单位
item[1].click()
time.sleep(2)
# 获取检查录入按钮
check_button = driver.find_elements_by_xpath('//span[@class="van-actionsheet__name"]')
# 单击检查按钮
check_button[0].click()
if __name__ == '__main__':
flag = True
# 如果已经打开
first_open(URL)
# exit()
# 获得打开后的网页driver
driver = get_web()
go_detail(driver)
time.sleep(5)
# get_info(driver)
# get_info(driver)
# inputs = driver.find_elements_by_xpath("//input[@class='van-field__control']")
# inputs[0].clear().send_keys('万习')
# inputs[1].clear().send_keys('12344555')
# print('hello')
# input('waiting.')
# name, phone, manager = write_info(driver)
# click_all(driver, name)
#
# driver.find_elements_by_xpath('//div[@class="saveBtn"]')[0].click()
input("waiting....")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/prcool/double-random-system.git
git@gitee.com:prcool/double-random-system.git
prcool
double-random-system
双随机系统
master

搜索帮助