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

中国网站为什么要备案网站制作入门

中国网站为什么要备案,网站制作入门,国外平面设计教程网站,做网站用angular目录 1、Selenium介绍 2、Selenium环境安装 3、创建浏览器、设置、打开 4、打开网页、关闭网页、浏览器 5、浏览器最大化、最小化 6、浏览器的打开位置、尺寸 7、浏览器截图、网页刷新 8、元素定位 9、元素交互操作 10、元素定位 #xff08;1#xff09;ID定位 1ID定位 2NAME定位 3CLASS_NAME定位 4TAG_NAME定位 5LINK_TEXT定位 6PARTIAL_LINK_TEXT定位 7CSS_SELECTOR定位 8XPATH定位 1、Selenium介绍 1自动化自动化是指使用技术手段模拟人工。执行重复性任务准确率100%高于人工。 2自动化应用场景自动化测试自动化运维自动化办公自动化游戏 3Selenium是web自动化中的知名开源库通过浏览器驱动控制浏览器通过元素定位模拟人工交换支持多种浏览器跨平台、兼容性高以实现web自动化无焦点状态依然执行 2、Selenium环境安装 1浏览器的安装 安装好了看版本右上角三个点-[帮助]-[关于Google Chrome ]然后关闭Chrome浏览器自动更新服务[开始搜索‘服务’关于Chrome的都可以禁用] 2浏览器驱动的安装 Chrome for Testing availability 保证浏览器与驱动大版本一致 下载后就可以拖到工程项目中了 3、创建浏览器、设置、打开 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动#创建设置浏览器对象 q1Options()#禁用沙盒模式 q1.add_argument(--no-sandbox)#保持浏览器打开状态默认是代码执行完毕后自动关闭 q1.add_experimental_option(detach,True)#创建并启动浏览器 a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1) 点击运行就会打开Chrome浏览器 注意沙盒模式在有些电脑必须设置的因为存在某些冲突所以必须设置但是大多数电脑时可以不用添加的 4、打开网页、关闭网页、浏览器 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 import time#设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func()#打开指定网址 a1.get(http:/baidu.com/) time.sleep(3) #关闭当前标签页[只会关闭一个标签页当只有一个标签页时就相当于关闭浏览器] a1.close() time.sleep(3) #退出浏览器 a1.quit()页面的渲染是需要花费时间的所以大家酌情添加time.sleep(second) 5、浏览器最大化、最小化 from os import times_resultfrom selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 import time#设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func()#打开指定网址 a1.get(http:/baidu.com/) time.sleep(2) #浏览器的最大化 a1.maximize_window() time.sleep(2) #浏览器的最小化 a1.minimize_window()6、浏览器的打开位置、尺寸 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 import time#设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func()#打开指定网址 a1.get(http:/baidu.com/) time.sleep(2) #浏览器的打开位置 a1.set_window_position(0,0) #浏览器打开尺寸 a1.set_window_size(600,600) 7、浏览器截图、网页刷新 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 import time#设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func()#打开指定网址 a1.get(http:/baidu.com/) time.sleep(2) #浏览器截图 a1.get_screenshot_as_file(1.png) time.sleep(2) #刷新当前网页 a1.refresh() 8、元素定位 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time#设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func()#打开指定网址 a1.get(http:/baidu.com/) time.sleep(2) #定位一个元素[找到的话返回结果找不到的话就会返回空列表] a2a1.find_element(By.ID,kw) print(a2)#定位多个元素[找到的话返回列表找不到的话直接报错] a3a1.find_elements(By.ID,kw) print(a3) 9、元素交互操作 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time#设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/baidu.com/) time.sleep(2) a2a1.find_element(By.ID,kw); #元素输入 a2.send_keys(自动化测试) time.sleep(2) #元素清空 a2.clear() time.sleep(2) #元素输入 a2.send_keys(测试) #元素点击 a1.find_element(By.ID, su).click() 10、元素定位 1ID定位 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time#设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/baidu.com/) time.sleep(2)#元素定位——ID #1、一般通过ID定位元素使比较准确的 #2、并不是所有的网页或者元素都有ID值 a1.find_element(By.ID,kw).send_keys(自动化测试) 2NAME定位 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time#设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/baidu.com/) time.sleep(2)#元素定位——NAME #1、一般通过name定位元素是比较准确的 #2、并不是所有的网页或者元素都有name值 a1.find_element(By.NAME,wd).send_keys(自动化测试) 3CLASS_NAME定位 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time #设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/baidu.com/) time.sleep(2)#元素定位——CLASS_NAME #1、class值不能有空格否则报错 #2、class值会有重复的所以需要切片处理 #3、class值有的网站是随机的这时候就不得不用别的定位方式哦 a1.find_elements(By.CLASS_NAME,c-font-normal)[1].click() 4TAG_NAME定位 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time #设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/bilibili.com/) time.sleep(2)#元素定位——TAG_NAME #找出开头便签名字 a1.find_elements(By.TAG_NAME,a)[6].click()5LINK_TEXT定位 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time #设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/baidu.com/) time.sleep(2)#元素定位——LINK_TEXT #通过精准链接文本找到标签a的元素[精准文本] #有重复的文本需要切片 a1.find_element(By.LINK_TEXT,新闻).click() 6PARTIAL_LINK_TEXT定位 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time #设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/bilibili.com/) time.sleep(2)#元素定位——PARTIAL_LINK_TEXT #通过模糊链接文本找到标签a的元素[模糊文本] #有重复的文本需要切片 a1.find_element(By.PARTIAL_LINK_TEXT,音).click() 7CSS_SELECTOR定位 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time #设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/baidu.com/) time.sleep(2)#元素定位——CSS_SELECTOR #1、通过id定位——#id #2、通过class值定位——.class #3、通过标签头定位——标签头 #4、通过任意类型定位[类型精准值] #5、通过任意类型定位[类型*模糊值] #6、通过任意类型定位[类型^开头值] #7、通过任意类型定位[类型$结尾值] a1.find_element(By.CSS_SELECTOR,#kw).send_keys(hello) 8XPATH定位 Copy XPath通过属性路径定位属性如果是随机的就定位不到 Copy full XPath完整路径缺点是定位值比较长优点是基本100%正确 from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time #设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/baidu.com/) time.sleep(2)#元素定位——XPath a1.find_element(By.XPATH,//*[idkw]).send_keys(hello) from selenium import webdriver #用于操作浏览器 from selenium.webdriver.chrome.options import Options #用于设置谷歌浏览器 from selenium.webdriver.chrome.service import Service #用于管理驱动 from selenium.webdriver.common.by import By import time #设置浏览器、启动浏览器 def func():q1Options()q1.add_argument(--no-sandbox)q1.add_experimental_option(detach,True)a1webdriver.Chrome(serviceService(chromedriver.exe),optionsq1)return a1 a1func() #打开指定网址 a1.get(http:/baidu.com/) time.sleep(2)#元素定位——XPath a1.find_element(By.XPATH,/html/body/div[1]/div[1]/div[5]/div/div/form/span[1]/input).send_keys(hello)
http://www.dnsts.com.cn/news/224333.html

相关文章:

  • 刚建设的网站如何推广wordpress转换为html
  • 深圳网站建设推广优化seo西安借贷购物网站建设
  • 在线生成固定悬浮导航的工具网站网站如何在推广
  • 零基础网站建设入门到精通视频教浅笑云虚拟主机
  • 网站建设卩金手指科杰十四一个网站域名多少钱
  • 网站cn和com有什么区别深圳网站制作hi0755
  • 深圳保障性住房官网贵阳关键词优化平台
  • 如何创建一个和淘宝一样的网站网站代码修改
  • 网站接做网站单小游戏网站网址
  • txt做网站如何加图片宁德市城乡建设网站
  • 惠州禅城网站建设大连企业网站建设定制
  • 遵义做百度网站一年多少钱中国企业建设网站
  • 私人做网站有什么用wordpress 免费建站
  • 宝山手机网站制作公司同程旅游
  • 漯河做网站xknt濮阳网站建设
  • 电子商务网站建设策划书范文中铁建设集团有限公司电话
  • 网站后台灰色工程建设专业
  • 创建网站目录结构应遵循的方法广州建设总承包集团
  • 网站开发怎么做软件开发者模式怎么打开
  • 个人网站设计模版html网站建设与管理作业
  • 内江如何做百度的网站wordpress竖排
  • wordpress滑动图片轮播福州百度seo
  • 网站制作前必须做的事情有哪些织梦dede建站教程视频
  • 邯郸市有搞网站服服务的吗网站如何更换空间
  • 网站seo链接购买微信管理软件哪个最好
  • 新手做网站盈利沈阳紧急通知
  • 论坛网站开发平台上海嘉定
  • 南通市网站建设我的完免费用搭建网站
  • 视频网站建设费用明细asp装修公司网站
  • 网站开发工作容易出现的失误phpcms 手机网站模板