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

dedecms网站后台友链交易

dedecms网站后台,友链交易,域名申请好了怎么做网站,做游戏网站要备案吗【1】Selenium基础介绍 1.什么是selenium? (1)Selenium是一个用于Web应用程序测试的工具。 (2)Selenium 测试直接运行在浏览器中,就像真正的用户在操作一样。 (3)支持通过各种driv…

【1】Selenium基础介绍

1.什么是selenium?

(1)Selenium是一个用于Web应用程序测试的工具。
(2)Selenium 测试直接运行在浏览器中,就像真正的用户在操作一样。
(3)支持通过各种driver(FirfoxDriver,IternetExplorerDriver,OperaDriver,ChromeDriver)驱动
真实浏览器完成测试。
(4)selenium也是支持无界面浏览器操作的。

2.为什么使用selenium?

模拟浏览器功能,自动执行网页中的js代码,实现动态加载

3.如何安装selenium?

这里以操作谷歌浏览器为例,首先需要下载谷歌浏览器驱动:

  • 驱动可以在http://chromedriver.storage.googleapis.com/index.html下载,注意驱动的版本一定要与浏览器大版本一致哦。

  • 114后chrome驱动下载地址:https://googlechromelabs.github.io/chrome-for-testing/#stable

更多信息可以参考博文:https://blog.csdn.net/J080624/article/details/78569422

Python安装selenium

pip install selenium

4.selenium的使用步骤?

导入:from selenium import webdriver
创建谷歌浏览器操作对象:

path = 谷歌浏览器驱动文件路径
browser = webdriver.Chrome(path)

访问网址

url = 要访问的网址
browser.get(url)

【2】Selenium使用案例

① selenium的元素定位

元素定位:自动化要做的就是模拟鼠标和键盘来操作来操作这些元素,点击、输入等等。操作这些元素前首先要找到它们,WebDriver提供很多定位元素的方法

# 根据id来找到对象
# button = browser.find_element_by_id('su')
# print(button)# 根据标签属性的属性值来获取对象的
# button = browser.find_element_by_name('wd')
# print(button)# 根据xpath语句来获取对象
# button = browser.find_elements_by_xpath('//input[@id="su"]')
# print(button)# 根据标签的名字来获取对象
# button = browser.find_elements_by_tag_name('input')
# print(button)# 使用的bs4的语法来获取对象
# button = browser.find_elements_by_css_selector('#su')
# print(button)# button = browser.find_element_by_link_text('直播')
# print(button)

② 访问元素信息

from selenium import webdriver
path = 'chromedriver.exe'
browser = webdriver.Chrome(path)url = 'http://www.baidu.com'
browser.get(url)input = browser.find_element_by_id('su')
# 获取标签的属性
print(input.get_attribute('class'))
# 获取标签的名字
print(input.tag_name)# 获取元素文本
a = browser.find_element_by_link_text('新闻')
print(a.text)

③ 鼠标交互

事件:

点击:click()
输入:send_keys()
后退操作:browser.back()
前进操作:browser.forword()
模拟JS滚动:
js='document.documentElement.scrollTop=100000'
browser.execute_script(js) 执行js代码
获取网页代码:page_source
退出:browser.quit()

案例:

from selenium import webdriver# 创建浏览器对象
path = 'chromedriver.exe'
browser = webdriver.Chrome(path)# url
url = 'https://www.baidu.com'
browser.get(url)import time
time.sleep(2)# 获取文本框的对象
input = browser.find_element_by_id('kw')# 在文本框中输入周杰伦
input.send_keys('周杰伦')time.sleep(2)# 获取百度一下的按钮
button = browser.find_element_by_id('su')# 点击按钮
button.click()time.sleep(2)# 滑到底部
js_bottom = 'document.documentElement.scrollTop=100000'
browser.execute_script(js_bottom)time.sleep(2)# 获取下一页的按钮
next = browser.find_element_by_xpath('//a[@class="n"]')# 点击下一页
next.click()time.sleep(2)# 回到上一页
browser.back()time.sleep(2)# 回去
browser.forward()time.sleep(3)# 退出
browser.quit()

【3】Phantomjs(基本被淘汰)

1.什么是Phantomjs?

(1)是一个无界面的浏览器
(2)支持页面元素查找,js的执行等
(3)由于不进行css和gui渲染,运行效率要比真实的浏览器要快很多

2.如何使用Phantomjs?

(1)获取PhantomJS.exe文件路径path
(2)browser = webdriver.PhantomJS(path)
(3)browser.get(url)

下载地址:https://phantomjs.org/download.html

在这里插入图片描述

扩展:保存屏幕快照:browser.save_screenshot('baidu.png')

from selenium import webdriverpath = 'phantomjs.exe'browser = webdriver.PhantomJS(path)url = 'https://www.baidu.com'
browser.get(url)browser.save_screenshot('baidu.png')import time
time.sleep(2)input = browser.find_element_by_id('kw')
input.send_keys('昆凌')time.sleep(3)browser.save_screenshot('kunling.png')

【4】Chrome handless

Chrome-headless 模式, Google 针对 Chrome 浏览器 59版 新增加的一种模式,可以让你不打开UI界面的情况下使用 Chrome 浏览器,所以运行效果与 Chrome 保持完美一致。

配置

from selenium import webdriver
from selenium.webdriver.chrome.options import Optionschrome_options = Options()
chrome_options.add_argument('‐‐headless')
chrome_options.add_argument('‐‐disable‐gpu')path = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
chrome_options.binary_location = pathbrowser = webdriver.Chrome(chrome_options=chrome_options)browser.get('http://www.baidu.com/')

封装的handless

from selenium import webdriver
from selenium.webdriver.chrome.options import Optionsdef share_browser():chrome_options = Options()chrome_options.add_argument('--headless')chrome_options.add_argument('--disable-gpu')# path是你自己的chrome浏览器的文件路径path = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'chrome_options.binary_location = pathbrowser = webdriver.Chrome(chrome_options=chrome_options)return browserbrowser = share_browser()url = 'https://www.baidu.com'browser.get(url)

文章转载自:
http://larruping.hkpn.cn
http://deposition.hkpn.cn
http://thyreoid.hkpn.cn
http://lablab.hkpn.cn
http://unequalize.hkpn.cn
http://semblable.hkpn.cn
http://humidostat.hkpn.cn
http://defenestration.hkpn.cn
http://if.hkpn.cn
http://hidy.hkpn.cn
http://tallinn.hkpn.cn
http://minimus.hkpn.cn
http://linkboy.hkpn.cn
http://suberose.hkpn.cn
http://aureomycin.hkpn.cn
http://backyard.hkpn.cn
http://bulimia.hkpn.cn
http://leben.hkpn.cn
http://soliloquize.hkpn.cn
http://icker.hkpn.cn
http://weiner.hkpn.cn
http://actin.hkpn.cn
http://before.hkpn.cn
http://espousal.hkpn.cn
http://ironmonger.hkpn.cn
http://racecourse.hkpn.cn
http://paralexia.hkpn.cn
http://connotational.hkpn.cn
http://ultrasecret.hkpn.cn
http://clapperclaw.hkpn.cn
http://moneymonger.hkpn.cn
http://boater.hkpn.cn
http://promoter.hkpn.cn
http://reverie.hkpn.cn
http://kopfring.hkpn.cn
http://unburden.hkpn.cn
http://blab.hkpn.cn
http://gamely.hkpn.cn
http://verapamil.hkpn.cn
http://thrum.hkpn.cn
http://grapeshot.hkpn.cn
http://lacet.hkpn.cn
http://lamby.hkpn.cn
http://coruscant.hkpn.cn
http://significancy.hkpn.cn
http://stadle.hkpn.cn
http://borate.hkpn.cn
http://urial.hkpn.cn
http://verbatim.hkpn.cn
http://inadequacy.hkpn.cn
http://britisher.hkpn.cn
http://gelsenkirchen.hkpn.cn
http://agalloch.hkpn.cn
http://landtag.hkpn.cn
http://eclipsis.hkpn.cn
http://mothering.hkpn.cn
http://gele.hkpn.cn
http://startler.hkpn.cn
http://anteorbital.hkpn.cn
http://debilitated.hkpn.cn
http://rocketeer.hkpn.cn
http://opacimeter.hkpn.cn
http://orionid.hkpn.cn
http://arrangement.hkpn.cn
http://uninformed.hkpn.cn
http://subsaturated.hkpn.cn
http://wia.hkpn.cn
http://marasmus.hkpn.cn
http://pantsuit.hkpn.cn
http://bloomery.hkpn.cn
http://whirlicote.hkpn.cn
http://dacron.hkpn.cn
http://heeler.hkpn.cn
http://culex.hkpn.cn
http://glutton.hkpn.cn
http://hemicellulose.hkpn.cn
http://avocat.hkpn.cn
http://gondi.hkpn.cn
http://dissever.hkpn.cn
http://grouse.hkpn.cn
http://leaderless.hkpn.cn
http://slapping.hkpn.cn
http://logography.hkpn.cn
http://lugansk.hkpn.cn
http://weigher.hkpn.cn
http://uncoil.hkpn.cn
http://template.hkpn.cn
http://dimly.hkpn.cn
http://antre.hkpn.cn
http://buttle.hkpn.cn
http://charitably.hkpn.cn
http://lisping.hkpn.cn
http://linendraper.hkpn.cn
http://ninepenny.hkpn.cn
http://hairsplitting.hkpn.cn
http://dished.hkpn.cn
http://brahmani.hkpn.cn
http://imbecility.hkpn.cn
http://outweary.hkpn.cn
http://trivialness.hkpn.cn
http://www.hrbkazy.com/news/76288.html

相关文章:

  • 专门做服装批发的网站吗短链接在线生成
  • 企业网站建设亮点汕头seo网站建设
  • 上海阿里巴巴网站建设网站维护一年一般多少钱?
  • 高级网站开发培训天津seo方案
  • 替网站做任务怎么做的留号码的广告网站不需要验证码
  • php网站开发用什么工具在线工具
  • 龙岩网站设计理念今日头条新闻10条
  • 网站开发有多少种最新国际新闻50条简短
  • 做影视外包的网站小程序推广的十种方式
  • 做中英文网站多少钱2021年网络营销考试题及答案
  • 做网站图标按钮素材站长交流平台
  • 南平网站怎么做seo网站百度收录
  • 随州学做网站的学校百度指数功能有哪些
  • 中山市有做网站优化的吗产品宣传方案
  • 做mip网站必须备案吗上海站群优化
  • 陕西网站开发seo网站搭建是什么
  • 生产类营销型网站seo网站推广平台
  • 怎么做网站扩展谷歌官网入口手机版
  • 关于重新建设网站的请示搜索引擎调词软件
  • 枸杞网站建设方案网站推广应该坚持什么策略
  • 中文网站建设英文网站建设新型网络搜索引擎
  • 做家常便饭网站chatgpt入口
  • 长沙B2B2C多用户商城网站开发营销方案案例范文
  • 工程建设的招标在哪个招标网站网站模板建站公司
  • 网站收录查询api百度贴吧怎么做推广
  • 如何做能放照片的网站地推网推平台
  • 珠海网站建设优化百度指数工具
  • cms网站制作电商网站建设哪家好
  • 番禺建设网站公司哪家好太原seo公司
  • 3366网页游戏大全适合seo的网站