当前位置:网站首页>Selenium's pull-down + headless browser
Selenium's pull-down + headless browser
2022-07-20 05:54:00 【Awning cute】
List of articles
The drop-down ???
Drop down refers to the drop-down options shown in the figure below , When we want to switch , You need to click the drop-down box first , Choose again
With Art, For example :
Navigate to the drop-down list
sel_el = web.find_element_by_xpath(‘//*[@id=“OptionDate”]’)Wrap the elements , Wrap into a drop-down menu
sel = Select(sel_el)Switch
- Switch by index
sel.select_by_index(i) # i Is the index value- By element value Switch
sel.select_by_value(value)- according to text Switch
sel.select_by_visible_text(text)
Be careful :
Every time you switch, you will send a network request , Time to load
Headless browser
Headless browser : It refers to the process of get In operation , The browser window will not pop up
How to get headless browser ?
With Chrome Browser as an example : Yes Chrome Make a configuration
- Import package
from selenium.webdriver.chrome.options import Options
- Prepare parameter configuration
opt = Options()
opt.add_argument(‘–headless’)
opt.add_argument(‘–disbale-gpu’)
- Set parameters in the browser
web = Chrome(options=opt)
example
import time
from selenium.webdriver import Chrome
from selenium.webdriver.support.select import Select
# Headless browser : The browser window will not pop up when running
# How to set up headless browser ?
# Yes Chrome Make a configuration
# 1. Import package
from selenium.webdriver.chrome.options import Options
# 2. Prepare parameter configuration
opt = Options()
opt.add_argument('--headless')
opt.add_argument('--disbale-gpu')
# 3. Set parameters in the browser
web = Chrome(options=opt)
# web = Chrome()
web.get('https://www.endata.com.cn/BoxOffice/BO/Year/index.html')
# Navigate to the drop-down list
sel_el = web.find_element_by_xpath('//*[@id="OptionDate"]')
# Wrap the elements , Wrap into a drop-down menu
sel = Select(sel_el)
# Let the browser adjust the options
for i in range(len(sel.options)): # there i Is the index position of each drop-down box option
sel.select_by_index(i) # Switch by index
# Be careful : Every time you switch, you will send a network request , Time to load
time.sleep(2)
table = web.find_element_by_xpath('//*[@id="TableList"]/table')
print(table.text)
print('================')
print(' The program is finished ')
web.close()
边栏推荐
- 毕业季&收获季,留下你的美好时刻
- An improved one millisecond mobile backbone paper notes
- js的【可选链】,【空值合并运算符】,【空值赋值运算符】用法和含义
- Intelligent cockpit fighting method of Internet manufacturers
- Interface testing -- custom assertion settings
- 字节跳动(抖音)软件测试月薪23K岗、技术二面面试题最新出炉
- 「接口测试入门课」打卡学习 day03:理解接口测试的关键逻辑
- FinalShell的介绍和使用
- 1304_FreeRTOS从任务控制块信息的角度尝试裁剪内核节省资源
- An Improved One millisecond Mobile Backbone 论文笔记
猜你喜欢
随机推荐
TCP实验验证
字节跳动(抖音)软件测试月薪23K岗、技术二面面试题最新出炉
Intelligent cockpit fighting method of Internet manufacturers
Docker安装Redis!!!(含每一步详细图解)实战
小白新手再启牛开通华泰账户安全吗?
VIM basic operation commands
visual studio西红柿插件过期解决办法——不断恢复试用
数据分析基础
WSL2 通过 USBIP 连接USB串口设备 JetsonUSB备份刷机
Wsl2 connects the USB serial port device jetsonusb backup brush through usbip
SQL time conversion format convert (varchar (10), field name, conversion format)
Install harbor on tke
FPS游戏逆向-方框透视(三角函数)
剑指Offer 42:连续子数组的最大和
Review of leetcode question brushing (question No.: 94, 17, interview questions 17, 102, 215, 1, 21)
VMware虚拟机的常规使用+快照
An improved one millisecond mobile backbone paper notes
Is it safe for novice Xiaobai to open Galaxy Securities again?
Interface testing -- custom assertion settings
LeetCode刷题回顾(题目编号:94、17、面试题17、102、215、1、21)