class Company(): companyName = " " # 企业名称 creditCode = " " # 统一信用代码 legalPerson = " " # 法定负责人 companyAddress = " " # 司注册地址 contactPerson = " " # 联系人 contactPersonPhone = " " # 联系人电话 villageId = "" # 乡镇
import xlrd from Tools import Py_Company def getCompanyName(): Open_Excel = xlrd.open_workbook("C:\Users\jiaow\Desktop\test.xlsx") sheet = Open_Excel.sheet_by_name("Sheet1") print("有效数据行数:",sheet.nrows,"行")#有效数据行数 print("有效数据列数:",sheet.ncols,"列")#有效数据列数 companyList = [] for i in range(sheet.nrows): if(i==0): continue company = Py_Company.Company() company.companyName = sheet.row_values(i)[0] print("企业名称:",company.companyName) company.creditCode = sheet.row_values(i)[1] print("统一信用代码:",company.creditCode) company.legalPerson = sheet.row_values(i)[2] print("法定负责人:",company.legalPerson) company.companyAddress = sheet.row_values(i)[3] print("公司注册地址:",company.companyAddress) company.contactPerson = sheet.row_values(i)[4] print("联系人:",company.contactPerson) company.contactPersonPhone = str(sheet.row_values(i)[5])[0:11] print("联系人电话:",company.contactPersonPhone) company.villageId = sheet.row_values(i)[6] print("乡镇归属:",company.villageId) companyList.append(company) return companyList # getCompanyName()
# -*- coding:utf-8 -*- #__author__ = "jiaoweinan" # date = 2021-1-13 from selenium import webdriver import time import datetime from selenium.webdriver.support.ui import Select from Tools import Excel_data from Logs import log def Data_ENTER(): chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option('useAutomationExtension', False) chrome_options.add_experimental_option("excludeSwitches", ['enable-automation']) driver = webdriver.Chrome(executable_path="C:Downloadchromedriver.exe", options=chrome_options) _url = "http://XXX.com/html/login.html" time.sleep(2) driver.get(_url) time.sleep(1) driver.find_element_by_id("username").send_keys("root") driver.find_element_by_id("password").send_keys("root") driver.find_element_by_id("submit").click() print("登录成功",datetime.datetime.now()) driver.find_element_by_xpath("/html/body/div[2]/div[3]/div/ul/li[2]/a").click() time.sleep(1) driver.find_element_by_xpath("/html/body/div[2]/div[3]/div/ul/li[2]/ul/li[3]/a").click() time.sleep(1) companyList = Excel_data.getCompanyName() for company in companyList: print(company) try: driver.find_element_by_id("add").click() time.sleep(Time) driver.find_element_by_id("companyName").send_keys(company.companyName) time.sleep(Time) S = driver.find_element_by_id("localAreaId") time.sleep(Time) Select(S).select_by_value("22") time.sleep(Time) S1 = driver.find_element_by_id("villageId") time.sleep(Time) Select(S1).select_by_visible_text(company.villageId1) time.sleep(Time) driver.find_element_by_id("creditCode").send_keys(company.creditCode) time.sleep(Time) driver.find_element_by_id("legalPerson").send_keys(company.legalPerson) time.sleep(Time) driver.find_element_by_id("companyAddress").send_keys(company.companyAddress) time.sleep(Time) js = "document.documentElement.scrollTop=1000" driver.execute_script(js) driver.find_element_by_id("contactPerson").send_keys(company.contactPerson) time.sleep(Time) driver.find_element_by_id("contactPersonPhone").send_keys(company.contactPersonPhone) time.sleep(Time) driver.find_element_by_id("businessLicensePhoto").send_keys("C:\Users\jiaow\Desktop\1.jpg") time.sleep(Time) driver.find_element_by_class_name("ui-button-text").click() time.sleep(5) try: driver.find_element_by_link_text("close").click() print("新增失败,信用代码:",company.creditCode,"时间:",datetime.datetime.now()) except: print("新增成功,信用代码:", company.creditCode, "时间:", datetime.datetime.now()) pass except Exception as e: print("报错信息:",e,"时间:",datetime.datetime.now()) log.initLogging("log.txt", Data_ENTER) Time = 0.5 # 输入间隔时间 Data_ENTER()