当前位置:网站首页>Learn to crawl steadily 08 - detailed explanation of the use method of selenium
Learn to crawl steadily 08 - detailed explanation of the use method of selenium
2022-06-22 01:58:00 【Smart Aries】
1 Set up the environment
1.1 install selenium
pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple
1.2 Install browser driver
First , Download browser driver :https://npm.taobao.org/mirrors/chromedriver, Then extract the browser driver chromedriver Put it in python The folder where the interpreter is located (python The folder where the interpreter is located :cmd-----where python) in .
2 Example
# Give Way selenium Launch Google browser
from selenium import webdriver
# from selenium.webdriver import Chrome
# 1、 Create a browser object
web = webdriver.Chrome()
# web = Chrome()
#2、 Open a web address
web.get("http://www.baidu.com")
3 Set up headless browser
from selenium.webdriver import Chrome
# Prepare the parameter configuration
opt = Options()
opt.add_argument('--headless')
opt.add_argument('--disable-gpu')
web = Chrome(options = opt) # Set the parameter configuration to the browser , It becomes a headless browser
web.get("http://www.baidu.com")
4 Switch windows
web.get("xxxxxxxx")
# stay selenium in , New windows do not switch by default
# Switch windows
web.switch_to.window(driver.window_handles[-1])
# Close subwindow
web.close()
# change selenium Window perspective , Go back to the original window
web.switch_to.window(driver.window_handles[0])
5 iframe Content acquisition in
# If you encounter iframe, You need to get iframe, And then switch to iframe visual angle , Then you can get the data
iframe = web.get('https://www.91kanju.com/vod-play/541-2-1.html')
web.switch_to.frame(iframe)
# Switch back to the original page
web.switch_to.default_content()
6 The solution for the program to be identified
6.1 chrome The version number of is less than 88
# When starting the browser ( No web content is loaded at this time ), Embed... Into the page js Code , Get rid of webdriver
web = Chrome()
web.execut_cdp_cmd("Page.asddScriptToEvaluateOnNewDocument"),{
"source":""" navigator.webdriver = undefined Object.defineProperty(navigator,'webdriver',{ get:() => undefined }) """
}
web.get(xxxxxx)
6.2 chrome The version number of is greater than 88
option = Options()
# Write but not write
#option.add_experimental_option('excludeSwitches',['enable-automatioin'])
option.add_argument('--disable-black-features = AutomationControlled')
web = Chrome(option = option)
web.get(xxxxxxx)
边栏推荐
- Packet capturing tool: Fiddler, a necessary skill for Software Test Engineer
- 2021 csp-j1 csp-s1 first round preliminary round related questions and videos
- 第 25 章 基于小波变换的数字水印技术
- LeetCode+ 46 - 50
- 第 21 章 路面裂缝检测识别系统设计--matlab深度学习实战
- 第 19 章 基于语音识别的信号灯图像模拟控制技术
- 数学知识复习:三重积分
- 第298场力扣周赛个人题解
- acwing 837. 连通块中点的数量 (并查集维护额外信息---集合数量)
- Five strokes first lesson fingering
猜你喜欢

【第 02 章 基于形态学的权重自适应图像去噪技术-全套系统MATLAB智能驾驶深度学习】
音视频学习路线及学习资料推荐

How to restore the IE browser auto jump edge

Recommended by Alibaba, Tencent and Baidu Software Test Engineers - rapid prototype model of software test model

Digital final notes

Intranet learning notes (3)

Chapter 03 extraction of anterior segment tissue based on multi-scale morphology - full system matlab intelligent driving in-depth learning

Appium面试题

第 19 章 基于语音识别的信号灯图像模拟控制技术

DAST 黑盒漏洞扫描器 第四篇:扫描性能
随机推荐
阿里腾讯百度软件测试工程师推荐——软件测试模型之快速原型模型
NOIP初赛 CSP-J1 CSP-S1 第1轮 初赛 信奥中的数学知识(一)
MBA-day24 最值问题
Intranet learning notes (9)
功能测试——MySQL数据库简介
GAMES-101-个人总结归纳-Transformation
Chapter 09 English printed character recognition based on feature matching matlab deep learning practical case
Test APK exception control sensor attacker development
Test case design method -- cause and effect diagram method
Google Earth Engine(GEE)——合并VCI指数和TCI温度得时序影像折线图(危地马拉、萨尔瓦多为例)
Mba-day24 best value problem
Mysql数据库轻松学09—数据分析师常用:数据查询语言DQL之多表查询
联发科技 --联发科技简介++附上笔经面经
Dachang NVIDIA face test questions sorting 123
第 24 章 基于 Simulink 进行图像和视频处理--matlab深度学习实战整理
Intel history overview
Fabric.js IText 手动设置斜体
Recommended by Alibaba, Tencent and Baidu Software Test Engineers - rapid prototype model of software test model
Creating a successful paradigm for cross-border e-commerce: Amazon cloud technology helps sellers lay out the next growth point
LeetCode+ 46 - 50