当前位置:网站首页>Web page automation practice "1. use the PY third-party library selenium to complete the access operation of elong"
Web page automation practice "1. use the PY third-party library selenium to complete the access operation of elong"
2022-06-21 16:04:00 【QingHan】
Catalog
- One 、 preparation
- 1. Create the corresponding project
- 2. What do you use python Environmental Science
- Two 、 Brief introduction selenium
- 1.selenium What does the kit contain
- 2. How to install
- 3. Import and stock in
- 4. Download the Google driver in the same version as the Google browser , And put the drive in py Under the installation path of , Google Chrome must be installed on c disc
- 3、 ... and 、 Code
One 、 preparation
1. Create the corresponding project
install python3.5 Above version , Do not install the latest version , Latest version python There may be a bug, The old version is more stable .
stay pycharm Click on the file---new project:
1) A virtual environment :
2) Local installed environment :
Maybe your computer has 37、38 Version of python.
Local system environment -- Select installation path :
Click on creat, Pop up the pop-up box , choice this window, Successfully created project .
The above two ways , Choose one to use , You can create corresponding projects .
2. What do you use python Environmental Science
expanded memory bank (External Libraries) The following shows python Environmental Science :
This is the environment I chose , Next, all the code runs in this environment , The third-party libraries to be installed in the future are all in this environment .
Two 、 Brief introduction selenium
selenium Is a web automation toolkit , The most popular open source web page operation tool .
1.selenium The kit contains :
Recording work -ide. Write code --webdriver. distributed processing --grid.
python--webdriver
1) Do you have the ability to solve problems . 2) Your local python Whether you have the ability to operate web pages . install python after , There is no default . To install a python Third party library ( Install external library , Let your local python Have corresponding ability ).
2. How to install ?
pip command . Online installation .pip install 1) Download the latest version . Version update . 2) If your third-party library has dependent Libraries , Then it will be installed for you automatically . python3 How many versions do you want ,pip The installed dependent libraries generally do not have any conflicts . 3) Where is it installed ? Which environment is the project , The required external libraries are installed in the environment .
3. Import and stock in :
from selenium import webdriver
ctrl+b Jump to view the source code of the library .
4. Download the Google driver in the same version as the Google browser , And put the drive in py Under the installation path of , Google Chrome must be installed on c disc
Download Google browser :https://www.chromedownloads.net/chrome64win/
Download the Google driver that matches the Google browser :https://chromedriver.chromium.org/downloads
32 Bit drive , Support at the same time 32 and 64 Bit windows10 System .
Select a non default path for browser installation , This is what many people often do in order not to occupy the system disk space . But for Selenium The environment is a little confused .
go back to Selenium Principle , When running code , Will pass ChromeDriver The plug-in starts a Socket Service and generate a Sessionid Open browser window , The browser window is opened to execute the application file of the browser ( Such as Chrome Of chrome.exe).
If the browser is installed in a non default path , Now Selenium Cannot find this binary chrome.exe The file throws an exception at this time :
WebDriverException:Message:unknown error:cannot find Chrome binary
The easiest way : Uninstall browser , Reinstall to the default path .
1. Google Chrome is on c Under my new folder
chromedriver.exe Put it in python Under the installation path of .
2. Google drives me on python Under the installation path of
Because... Has been configured python The installation path of is the system variable --path Environment variables under , So there is no need to configure Google driven environment variables .
3. Because the browser is not installed with , It is a compressed package . Remember to configure the decompressed path of the Google browser zip to the environment variable - System variables -path In the middle , Otherwise, the running code will report an error and cannot find the Google driver .
Reference link :https://blog.csdn.net/ouyanggengcheng/article/details/90476553
( Group Friends reply : All afternoon , Finally solve , The best way is to reinstall chrome, Let him be in the default position , I used the following add browser location , But it doesn't work )
If the correct configuration is still not available , Be sure to restart the computer .
3、 ... and 、 Code
'''
1、 .py suffix .
2、python Language .
chinese -- Grammatical expression . Rule of grammar .
having dinner
train
high-speed rail
Cash machine
english
'''
# 1、 alignment .
# print It's a built-in function , For output . Console output .
# print("hello")# Under no special circumstances , The code is written in the top grid .
# # 2、 Line break . One sentence, one line .
# print("daydayup")
# Use code to operate the browser .
from selenium import webdriver
# Open Google browser , Established a session with the browser .
#driver Variable = conversation .
driver=webdriver.Chrome()# Google Chrome's name is capitalized .
# Based on this conversation , Visit a web page .
#webdriver Is a third-party library . Provides a variety of web page operations API. That's the method .
# The method of accessing a web page is called get().
driver.get("https://www.elong.com/")#driver This variable does , Is based on webdriver.Chrome() This conversation .
# get() It's called .
'''
Variable = value
Variable name : Numbers / character (26 It's a case letter )/_
Start with a string , Underline stitching .
my_name
Variable names are never used in Chinese .
The shopping cart : Push / Pulling / Mentioned .
Variable : Variable = data . Integers / character string
A variable used to store data . One definition , Used multiple times .
The shopping cart / Lockers --1 A Durian .
The shopping cart =1 A Durian .
Get durian , Find the shopping cart .
python Finding this variable in is equivalent to finding this data .
Shopping cart can be visited many times .
character string 、 character string , Is to connect the characters together , String in a string, string in a string ;
The string can contain numbers 、 Letter 、 Special symbols, etc .
stay Python Just add a pair of double quotation marks or a pair of single quotation marks to some contents ,
The default is string ;( Three pairs of single quotation marks or three pairs of double quotation marks can be used to write multiline strings ).
'''
# gwc=" A Durian "# With double quotation marks , It's just a string .
# gwc=100
# money=99
# me=" beauty "
边栏推荐
- Schéma de développement du système d'échange décentralisé uniswap
- Typescript (6) function
- 使用APICloud实现文档下载和预览功能
- Gmail: how to track message reading status
- Using apiccloud to realize document download and Preview
- Research Report on the overall scale, major manufacturers, major regions, products and application segments of twin-screw superchargers in the global market in 2022
- Review: effects of repetitive transcranial magnetic stimulation rTMS on resting state functional connectivity
- 天天预约排队助手|使用手册
- When Huawei order service is called to verify the token interface, connection reset is returned
- Research Report on the overall scale, major manufacturers, major regions, products and application segments of roots superchargers in the global market in 2022
猜你喜欢

旭日图有效展示数据的层级和归属关系

Perfect partner of ebpf: cilium connected to cloud native network

Mid year summary of 33 year old programmer

GO语言-指针

Score-Based Generative Modeling through Stochastic Differential Equations

天天预约排队助手|使用手册

【数论】leetcode1006. Clumsy Factorial

2 万字 + 30 张图 | 细聊 MySQL undo log、redo log、binlog 有什么用?

Comprehensive learning notes for intermediate network engineer in soft test (nearly 40000 words)

WEB3 安全系列 || 攻击类型和经验教训
随机推荐
Elastic stack Best Practices Series: a filebeat memory leak analysis and tuning
目前哪个期货公司开户比较好?请问手续费低、交易又安全?
Isn't this another go bug?
20000 words + 30 pictures | what's the use of chatting about MySQL undo log, redo log and binlog?
Blazor overview and routing
高级性能测试系列《4.性能测试的前提、性能测试工具、性能测试流程》
Uniswap去中心化交易所系统开发方案
Set up your own website (4)
Uniswap decentralized exchange system development scheme
Score-Based Generative Modeling through Stochastic Differential Equations
关于cookie和session的一些理解
TypeScript(6)函数
Web网页自动化实战《2.在艺龙网中,根据城市+日期+关键词精准匹配了酒店》上篇
Uniswap去中心化交易所系統開發方案
Some understanding of cookies and sessions
The out of the box caching function of angular server-side rendering applications
What is the difference between everything, gnomelive, kdelive, livecd and netinstall in the image?
Web网页自动化实战《5.获取所有酒店的名字、价格、评分信息,并写入文件》下篇
Distributed monomer brought by microservice architecture
原生JS路由,iframe框架