Skip to content

Python Selenium Introduction and Setup

Python Selenium

The purpose of this tutorial is to introduce you to Selenium and show the process of installing selenium and webdriver for browser automation. In this article, we’ve assumed that you already have python installed on your machine.

It’s an important point to note that Browser automation and Web Scrapping are completely White Hat in their approach and the Web Browsers themselves support it officially, provide web drivers for automation and testing, just the browser window opened using code is labeled as “this browser is being controlled by automated test software”

What is Selenium?

Selenium is an open-source project which provides a wide range of tools to automate the web browser. It is also used to create web scrapers to obtain(scrape) desired data from web pages.

Some tasks that can be done using Python Selenium are:

  • Automating Browser tasks such as login, meeting join, scrolling, surfing, etc.
  • Getting Data from Website/webpage in text, excel file, code, etc.

A crucial component in browser automation is a Webdriver. A Webdriver is a collection of APIs which makes interaction with the browser easy. Combining Selenium and webdriver make it very easy to automate boring tasks of the web.

Installing Selenium

To start with setting up our computer for browser automation and web scraping, we need to start with the installation of some tools and libraries.

1. Install Selenium

First we’ll install the selenium package using pip. It is very easy to install any python package using the pip install package_name command.

Open the command prompt of your computer and enter the below command. You can also run the command in the terminal of your system or IDE.

pip install selenium

It will install the latest version of selenium on our machine.

2. Install the Selenium Webdriver

Our second task, in setting up is to install the webdriver as per our browser, which we intend to use to automate.

While installing the webdriver we need to make sure that it has the same version as our Web Browser. Every browser has its own webdriver which is maintained by its parent companies.

Below are the links for downloading webdriver of the popular Web Browers – Mozilla Firefox, Google Chrome, and Microsoft Edge respectively.

To download Mozilla Firefox Webdriver: here
To download Google Chrome Webdriver: here
To download Microsoft Webdriver: here

After downloading selenium and the required webdriver, you are ready to write python scripts to automate the web browser.

3. Importing Selenium in Python

As we have downloaded the required tools and libraries, as a final step we need to import the required as follow:

Note: We need to pass the location (as saved on our computer) of the installed web driver file to the webdriver method.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome('C://software/chromedriver.exe')

Tip: Instead, of passing the location as a parameter every time, in every code, we can skip this step in a smart way by declaring (saving) the location of the downloaded web driver file as an environment variable.

Finally, we are done with the setup and you may start web scraping and automating your web browser tasks by following our tutorials on Python Selenium –

  • Open Web Page URLs using Python Selenium
  • Fetch data from a web page
  • Fetch Stock Market data using Selenium

哆哆女性网精灵宝可梦破解版无限钻石全部淘宝网站设计多少钱周易全书 pdf免费孩子取名起名大全网站上海企业seo顾问北京wap网站建设生辰八字免费起名打分100分的清字的艺术签名惠普电脑怎么样角点定制网站建设教育公司起名大全梦幻模拟战破解版下载只有我们知道的地方周易免费生辰八字取名字宁波起名取名资产管理周公解梦泥鳅嘉字艺术签名家庭农场起个名字男孩缺金缺火起名字市网站建设李的男孩子起什么名字周易在线取名云监工武汉做seo的公司适合女孩起名字的成语济宁建设网站网络营销推广 企业起名字姓韩女孩鼠年生的男孩起名淀粉肠小王子日销售额涨超10倍罗斯否认插足凯特王妃婚姻不负春光新的一天从800个哈欠开始有个姐真把千机伞做出来了国产伟哥去年销售近13亿充个话费竟沦为间接洗钱工具重庆警方辟谣“男子杀人焚尸”男子给前妻转账 现任妻子起诉要回春分繁花正当时呼北高速交通事故已致14人死亡杨洋拄拐现身医院月嫂回应掌掴婴儿是在赶虫子男孩疑遭霸凌 家长讨说法被踢出群因自嘲式简历走红的教授更新简介网友建议重庆地铁不准乘客携带菜筐清明节放假3天调休1天郑州一火锅店爆改成麻辣烫店19岁小伙救下5人后溺亡 多方发声两大学生合买彩票中奖一人不认账张家界的山上“长”满了韩国人?单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#青海通报栏杆断裂小学生跌落住进ICU代拍被何赛飞拿着魔杖追着打315晚会后胖东来又人满为患了当地回应沈阳致3死车祸车主疑毒驾武汉大学樱花即将进入盛花期张立群任西安交通大学校长为江西彩礼“减负”的“试婚人”网友洛杉矶偶遇贾玲倪萍分享减重40斤方法男孩8年未见母亲被告知被遗忘小米汽车超级工厂正式揭幕周杰伦一审败诉网易特朗普谈“凯特王妃P图照”考生莫言也上北大硕士复试名单了妈妈回应孩子在校撞护栏坠楼恒大被罚41.75亿到底怎么缴男子持台球杆殴打2名女店员被抓校方回应护栏损坏小学生课间坠楼外国人感慨凌晨的中国很安全火箭最近9战8胜1负王树国3次鞠躬告别西交大师生房客欠租失踪 房东直发愁萧美琴窜访捷克 外交部回应山西省委原副书记商黎光被逮捕阿根廷将发行1万与2万面值的纸币英国王室又一合照被质疑P图男子被猫抓伤后确诊“猫抓病”

哆哆女性网 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化