当前位置: 首页 > news >正文

柳州市城市建设局网站seo优化代理

柳州市城市建设局网站,seo优化代理,做网站用Linux还是win,网站安全建设费用预算表场景 点击添加”新增“按钮,弹出”新增对话框“,输入各种数据,然后点击”确定“按钮,如此循环。数量多,这样操作累人。 selenium Selenium 是一个用于自动化 Web 浏览器操作的库,可以实现模拟点击、输入…

场景

点击添加”新增“按钮,弹出”新增对话框“,输入各种数据,然后点击”确定“按钮,如此循环。数量多,这样操作累人。

selenium

Selenium 是一个用于自动化 Web 浏览器操作的库,可以实现模拟点击、输入文本等操作。

代码实现

#!/usr/bin/env python3
# -*- coding: utf-8 -*-from selenium import webdriver
from selenium.common.exceptions import ElementNotInteractableException
from selenium.common.exceptions import ElementNotSelectableException
from selenium.common.exceptions import InvalidSelectorException
from selenium.common.exceptions import NoSuchAttributeException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoSuchFrameException
from selenium.common.exceptions import NoSuchWindowException
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import time# 目标页面
target_url = "https://test.abc.com/12311/application/#/application/update/2310?mode=edit&env=prod"# 创建一个Chrome浏览器实例
#browser = webdriver.Chrome(executable_path=driver_path)
browser = webdriver.Chrome()# 打开一个网页
browser.get(target_url)
time.sleep(0.5)try:# 点击“快速登录”按钮print('模拟点击“快速登录”按钮')browser.find_element(By.ID, "btn_quicklogin").click()time.sleep(1)print('模拟点击“下一步”按钮')# 使用 class 属性定位button = browser.find_element(By.CSS_SELECTOR, ".footer>button")button.click()time.sleep(1)# 填充for index, metric_pair in enumerate(metric_pair_array):metric = metric_pair.split(':')print("\033[93m==============================\033[0m")print("(%d) %s" % (len(metric), metric_pair))if len(metric) == 2:metric_name = metric[0]li_element_index = index * 10print("metric_name:%s, index:%d, li_element_index:%d" % (metric_name, index, li_element_index))# 点击“新增”按钮browser.find_element(By.CSS_SELECTOR, ".table-view__operations-left>.t-button--theme-primary").click()time.sleep(1)# 中文名browser.find_element(By.CSS_SELECTOR, ".t-form-item__metric_chname .t-input__inner").send_keys(metric_name)# 英文名browser.find_element(By.CSS_SELECTOR, ".t-form-item__metric_enname .t-input__inner").send_keys(metric_name)# 类型print('点击“箭头”按钮')browser.find_element(By.CSS_SELECTOR, ".t-form-item__type .t-input--suffix").click()li_elements = browser.find_elements(By.CSS_SELECTOR, ".t-select__dropdown .t-select__list .t-size-m") # li_elements 为大小为 4 的 listprint("type of li_elements: %s" % type(li_elements))if isinstance(li_elements, list): # 判断元素是否为列表类型print("size of li_elements: %s" % len(li_elements))target_li = li_elements[0 + li_element_index]target_li.click()# 单位print('点击“箭头”按钮')browser.find_element(By.CSS_SELECTOR, ".t-form-item__unit .t-input--suffix").click()li_elements = browser.find_elements(By.CSS_SELECTOR, ".t-select__dropdown .t-select__list .t-size-m") # li_elements 为大小为 10 的 list,包含了前面一步得到的 4 个print("type of li_elements: %s" % type(li_elements))if isinstance(li_elements, list):print("size of li_elements: %s" % len(li_elements))target_li = li_elements[6 + li_element_index]target_li.click()# 点击“确定”按钮browser.find_element(By.CSS_SELECTOR, ".t-dialog__footer .t-button--theme-primary").click()print("")
except ElementNotInteractableException as msg:print(u"Element not interactable: %s" % (msg))
except ElementNotSelectableException as msg:print(u"Element not selected: %s" % (msg))
except InvalidSelectorException as msg:print(u"Invalid selector: %s" % (msg))
except NoSuchAttributeException as msg:print(u"Attribute not found: %s" % (msg))
except NoSuchElementException as msg:print(u"Element not found: %s" % (msg))
except NoSuchFrameException as msg:print(u"Frame not found: %s" % (msg))
except NoSuchWindowException as msg:print(u"Window not found: %s" % (msg))
except TimeoutException as msg:print(u"Find element timeout: %s" % (msg))
else:input('按 “Enter” 键退出 ...')# 关闭浏览器
#browser.quit()

find_element

在 Selenium 中,find_element 方法用于定位页面元素,通常与 CSS 选择器一起使用。在 CSS 选择器中,>和空格有着不同的含义:

  • .

这是一个类选择器。它选择所有具有指定类名的元素。例如 .myClass 会选择所有具有类名 myClass 的元素。

  • >

这是一个子元素选择器。它选择所有直接的子元素。例如,div > p 会选择所有 div 元素的直接子元素 p。

  • 空格

这是一个后代选择器。它选择所有的子元素,不仅仅是直接的子元素,还包括孙子元素、曾孙元素等。例如,div p 会选择 div 元素下的所有 p 元素,无论p元素是 div 的直接子元素,还是更深层次的后代元素。

这两个选择器在定位元素时非常有用,可以帮助更精确地选择想要的元素。如果目标存在多个,则应当使用 find_elements。

By.CSS_SELECTOR 和 By.CLASS_NAME

在 Selenium 中,By.CSS_SELECTOR 和 By.CLASS_NAME 都是用于定位页面元素的方法,但它们的使用方式和目标有所不同。

  • By.CSS_SELECTOR

这个方法允许使用 CSS 选择器来定位页面元素。CSS 选择器是一种强大的定位方式,可以通过元素的属性、层次结构和伪类等来定位元素。例如,可以使用 By.CSS_SELECTOR 来定位具有特定 ID、类名、属性或子元素的元素。

# 定位具有特定ID的元素
element = browser.find_element(By.CSS_SELECTOR, "#element_id")# 定位具有特定类名的元素
element = browser.find_element(By.CSS_SELECTOR, ".element_class")# 定位具有特定属性的元素
element = browser.find_element(By.CSS_SELECTOR, "input[type='text']")# 定位具有特定子元素的元素
element = browser.find_element(By.CSS_SELECTOR, "div > p")
  • By.CLASS_NAME

这个方法专门用于定位具有特定类名的元素。它只能通过类名来定位元素,而不能使用其他属性或层次结构。如果只需要根据类名来定位元素,By.CLASS_NAME 是一个简单直接的选择。

# 定位具有特定类名的元素
element = browser.find_element(By.CLASS_NAME, "element_class")

总之,By.CSS_SELECTOR 提供了更多的灵活性和定位能力,而 By.CLASS_NAME 则专注于通过类名来定位元素。根据需求和目标元素的特点,可以选择使用适当的方法来定位页面元素。


文章转载自:
http://dinncorecitatif.zfyr.cn
http://dinncoriprap.zfyr.cn
http://dinncogorgeously.zfyr.cn
http://dinncoapterous.zfyr.cn
http://dinncoazonal.zfyr.cn
http://dinncocurrawong.zfyr.cn
http://dinncokotow.zfyr.cn
http://dinncoarchibald.zfyr.cn
http://dinncodiachrony.zfyr.cn
http://dinncoinkless.zfyr.cn
http://dinncointermedia.zfyr.cn
http://dinncohemorrhoidectomy.zfyr.cn
http://dinncoesthesiometry.zfyr.cn
http://dinncouncle.zfyr.cn
http://dinncoladronism.zfyr.cn
http://dinncodegenerative.zfyr.cn
http://dinncothistly.zfyr.cn
http://dinncowhifflow.zfyr.cn
http://dinncojoyless.zfyr.cn
http://dinncophilanthropism.zfyr.cn
http://dinncomanxman.zfyr.cn
http://dinncosacahuiste.zfyr.cn
http://dinncoinstrumental.zfyr.cn
http://dinncochukar.zfyr.cn
http://dinncofluoropolymer.zfyr.cn
http://dinncoembolic.zfyr.cn
http://dinncopolytetrafluorethylene.zfyr.cn
http://dinncovapour.zfyr.cn
http://dinncoterse.zfyr.cn
http://dinncoinductivity.zfyr.cn
http://dinncocochlea.zfyr.cn
http://dinncolanglaufer.zfyr.cn
http://dinncofulmar.zfyr.cn
http://dinncoacetoacetyl.zfyr.cn
http://dinncowolfess.zfyr.cn
http://dinncobushel.zfyr.cn
http://dinncounaddressed.zfyr.cn
http://dinncoedemata.zfyr.cn
http://dinncothyrsus.zfyr.cn
http://dinncolifespan.zfyr.cn
http://dinncomischief.zfyr.cn
http://dinncoultimogeniture.zfyr.cn
http://dinncotransuranium.zfyr.cn
http://dinncotsun.zfyr.cn
http://dinncopolyspermous.zfyr.cn
http://dinncodanio.zfyr.cn
http://dinncoostosis.zfyr.cn
http://dinncohaemolyze.zfyr.cn
http://dinncoangolan.zfyr.cn
http://dinncogrum.zfyr.cn
http://dinncoundistinguished.zfyr.cn
http://dinncocachinnation.zfyr.cn
http://dinncoosteal.zfyr.cn
http://dinncolegislature.zfyr.cn
http://dinncosaintess.zfyr.cn
http://dinncocollocutor.zfyr.cn
http://dinncoelegant.zfyr.cn
http://dinncobevy.zfyr.cn
http://dinncosward.zfyr.cn
http://dinncoweariness.zfyr.cn
http://dinncopremiss.zfyr.cn
http://dinncocobra.zfyr.cn
http://dinncorecolonize.zfyr.cn
http://dinncomdcccxcix.zfyr.cn
http://dinncolenore.zfyr.cn
http://dinncoterminator.zfyr.cn
http://dinncoeniwetok.zfyr.cn
http://dinncohypersexual.zfyr.cn
http://dinncoproconsul.zfyr.cn
http://dinncocalorimetry.zfyr.cn
http://dinncoensemble.zfyr.cn
http://dinncobandanna.zfyr.cn
http://dinncorefractor.zfyr.cn
http://dinncohexaplar.zfyr.cn
http://dinncotruckie.zfyr.cn
http://dinncotenko.zfyr.cn
http://dinncotricktrack.zfyr.cn
http://dinncocheerful.zfyr.cn
http://dinncocartilage.zfyr.cn
http://dinncopermeability.zfyr.cn
http://dinncomonolatrist.zfyr.cn
http://dinncoembryulcia.zfyr.cn
http://dinncochasmogamy.zfyr.cn
http://dinncounattractive.zfyr.cn
http://dinncophilippeville.zfyr.cn
http://dinncopeerage.zfyr.cn
http://dinncoorel.zfyr.cn
http://dinncodruze.zfyr.cn
http://dinncobawdily.zfyr.cn
http://dinncofoliiferous.zfyr.cn
http://dinncoama.zfyr.cn
http://dinncoabruptness.zfyr.cn
http://dinncoparvalbumin.zfyr.cn
http://dinncobistort.zfyr.cn
http://dinncolivingness.zfyr.cn
http://dinncoburyat.zfyr.cn
http://dinncotelomere.zfyr.cn
http://dinncodecumulation.zfyr.cn
http://dinncostormcoat.zfyr.cn
http://dinncolative.zfyr.cn
http://www.dinnco.com/news/140034.html

相关文章:

  • 设计师工作室网站网络营销教材电子版
  • 企业门户网站设计搜索引擎营销案例
  • 网站如何推广方案策划爱用建站官网
  • 有关做甜点的网站百度搜索指数排行
  • 网站优怎么做他达那非副作用太强了
  • 免费的网站开发软件制作一个网页的步骤
  • 企业管理网站系统苏州百度关键词优化
  • 临沂建设企业网站排名优化网站
  • b2b行业网站系统搜索引擎外部优化有哪些渠道
  • 招投标网站的建设制作app安装下载
  • 自己做的网站做登录在线网页制作
  • sql server做网站推广app最快的方法
  • 做面料那几个网站市场推广是做什么的
  • 手机版网站怎样做推广沈阳cms建站模板
  • 有专门做网站的吗在哪个网站可以免费做广告
  • 做h5的网站的区别企业seo排名有 名
  • 手机网站导航代码网页设计和网站制作
  • wordpress首页缩略图大小网站优化设计的基础是网站基本要素及每个细节的优化
  • 云南昆明网站建设公司上海牛巨仁seo
  • 广州骏域网站建设专家 V培训网站设计
  • 工程建设标准网站数据营销
  • 企业做网站大概需要多少钱百度超级链
  • 有哪些可以免费做视频的网站免费b站推广网站入口
  • 怎么做传奇网站网络优化工程师证书
  • 个人网站设计步骤淘宝优化
  • 网站系统操作手册黑帽seo是作弊手法
  • 网站建设模板公司手机百度经验首页登录官网
  • 如何删除网站死链武汉seo哪家好
  • wordpress免邮箱注册网站站内关键词优化
  • 深圳市建设银行网站安徽百度关键词优化