首页 > 其他分享 >核酸管理网站爬取

核酸管理网站爬取

时间:2022-09-28 06:11:05浏览次数:52  
标签:index point 网站 list driver element 爬取 核酸 find

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
import datetime

# date = str(datetime.date.today()-datetime.timedelta(1)) # 日期是昨天,用于次日一早检测昨天没有完成的
date = str(datetime.date.today())    # 日期是今天,用于检测当天没有完成的

driver = webdriver.Chrome()
driver.implicitly_wait(30)
driver.get("http://218.59.156.206:8888/bims/")
driver.maximize_window()

driver.find_element(By.ID, "userName").send_keys('')  # 账号
driver.find_element(By.NAME, "password").send_keys('')  # 密码
driver.find_element(By.XPATH, "//form/div[3]/input").click()  # 点击登陆


point = driver.find_element(By.XPATH, "//*[@id='mainSplitter']/div[3]/div/ul/li") # 找到地球图标元素
ac = ActionChains(driver)
ac.click(point).perform()                             # 点击图标,出现人员管理,核减删除
time.sleep(1)
ac.move_to_element_with_offset(point, 108, 46).click().perform()  # 点击核减删除
ac.move_to_element_with_offset(point, 200, 200).perform()         # 点击别处,让核减删除消失

time.sleep(1)
iframe = driver.find_element(By.ID, "mainFrame")      # 切换到iframe
driver.switch_to.frame(iframe)
ac = ActionChains(driver)
point = driver.find_element(By.XPATH, "//*[@id='toolbar']/div[3]/div/button")  # 找到 核减人员,删除人员 按钮 点击
ac.click(point).perform()
time.sleep(1)
ac.move_to_element_with_offset(point, 0, 68).click().perform()                # 点击删除人员,让其复选框消失

point = driver.find_element(By.XPATH, '//button/span[@class="page-size"]')   # 找到每页显示 按钮,点击
ac.click(point).perform()
time.sleep(1)
ac.move_to_element_with_offset(point, 0, -35).click().perform()             # 在出现的每页显示500上点击

fo = open("d:/stu.txt", "w", 2048)                          # fo 文件输出全部人员的 姓名 身份证 本周次数 核检日期 时间
fe = open("d:/no.txt", "w", 2048)                           # fe 文件输出本日没有做核酸的人员信息

driver.find_elements(By.XPATH,"//tr[@date-index='0']")   # 如果第一个tr找到,说明已经加载完成
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")   # 产生本页存放人员信息的tr标签的列表
for td in points:                                   # 遍历tr标签列表
    list_ = td.text.split(' ')  # 对tr标签的文本按照空格切割得到字符串列表,列表元素:姓名 身份证号 手机 地址 次数 日期 时间 ....
    index = 3                                       # 如果没有地址,列表索引3 为次数
    if len(list_[4])==1:                           
        index = 4                                  # 如果有地址,列表索引4 为次数
    elif len(list_[5])==1:
        index = 5                                  # 如果有地址但是地址中有空格,列表索引5 为次数
    fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index] + "\t" + list_[index+1] + "\t" + list_[index+2]  + "\n" ) # 写入fo文件
    if list_[index+1]!= date:                     # 如果日期不是今天的日期,说明今天没有做,存入fe文件
        fe.write(list_[1][6:10] + list_[1][15:] + list_[0]  + "\n")  # 格式为出生年4位+身份证最后3位+姓名
        
        
driver.find_element(By.LINK_TEXT, "2").click()    # 找到第二页按钮,点击
driver.find_elements(By.XPATH,"//tr[@date-index='0']")
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
    list_ = td.text.split(' ')
    index = 3
    if len(list_[4])==1:
        index = 4
    elif len(list_[5])==1:
        index = 5
    fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index] + "\t" + list_[index+1] + "\t" + list_[index+2]  + "\n" )
    if list_[index+1]!= date:
        fe.write(list_[1][6:10] + list_[1][15:] + list_[0]  + "\n")
    
driver.find_element(By.LINK_TEXT, "3").click()            # 找到第三页按钮,点击
driver.find_elements(By.XPATH,"//tr[@date-index='0']")
points = driver.find_elements(By.XPATH, "//*[@id='rightTable']/tbody/tr")
for td in points:
    list_ = td.text.split(' ')
    index = 3
    if len(list_[4])==1:
        index = 4
    elif len(list_[5])==1:
        index = 5
    fo.write(list_[0] + "\t" + list_[1] + "\t" + list_[index] + "\t" + list_[index+1] + "\t" + list_[index+2]  + "\n" )
    if list_[index+1]!= date:
        fe.write(list_[1][6:10] + list_[1][15:] + list_[0]  + "\n")
        #fe.write(list_[0] + list_[1][15:] + "\n") 
        # fe.write(list_[0] + "\t" + list_[1] + "\t" + list_[index] + "\t" + list_[index+1] + "\t" + list_[index+2] + "\n")
fo.close()
fe.close()
print("end!")

标签:index,point,网站,list,driver,element,爬取,核酸,find
From: https://www.cnblogs.com/sunwenping/p/16736638.html

相关文章

  • 多线程爬取wallhaven
    前言最近整理自己的项目时,发现之前自己写的爬取wallhaven网站顿时有来的兴趣决定再写一遍来回顾自己以前学的知识网站地址:"https://wallhaven.cc/"1.url参数结构从ur......
  • 冰河常逛的23大学习网站(建议收藏)!!
    小伙伴们有木有这种感觉:假期还没怎么玩就已经过去了?好吧,其实,冰河也有这种感觉:假期还没开始就已经结束了。哎,我们还是把心收回来,好好工作吧!国庆期间有小伙伴问我:冰河,你有啥......
  • 5个cpp学习网站
    5个学习cpp的网站相对其他语言来说,C++算是难度比较高的了,这一点无法否认。但是如果能有一些好的网站,则会让C++的学习事半功倍。那就来介绍几个最常用的(最好的)吧,包含了......
  • 直播网站源码,点击按钮Button,更换背景颜色
    直播网站源码,点击按钮Button,更换背景颜色代码实现drawable目录下:1、btn_nopress_shape.xml <?xmlversion="1.0"encoding="utf-8"?><shapexmlns:android="http://......
  • nginx配置前端网站
    主要是改location/{roothtml;indexindex.htmlindex.htm;} 这表示默认的网站是nginx的html文件夹。假如我们写的前端项目文件打包后是dist。......
  • 爬取某东的小米的手机信息20页 用selenium来爬取
    importtime#fromseleniumimportwebdriverfromselenium.webdriver.chrome.serviceimportServicefrombs4importBeautifulSoupfromselenium.webdriver.commo......
  • Python爬取全球疫情数据,制作数据可视化图
    前言开发环境python3.8:解释器pycharm:代码编辑器requests发送请求pyecharts绘制图表pandas读取数据爬虫案例思路流程:一.数据来源分析:......
  • 国内多地测试网站访问速度
    有时候我们项目在本地域挺快的,但是在国内其他地方就比较慢这个时候可以使用下面的网站测试,能测试其他地方的访问速度https://www.17ce.com/ 我的在线客服系统效果如图......
  • 7、如何搭建一个网站
    ......
  • 批量爬取抖音视频
    先创建dou_url.txt,其实不用创建也行,运行第一遍代码的时候程序会自动创建dou_url.txt里面可以填写多个视频url即可爬取,也可以填url加文字,因为用了正则表达式匹配。。。比......