In this second demo,
you'll get to learn how to open a web page using the WebDriver.
This demo serves two purposes.
The first is, as stated,
you'll get to see how to open a web page with the WebDriver,
which is the first step to creating a dynamic web page.
The second is,
you'll get to see if all of your package installations from the
previous demo work correctly and are in place.
So let's get to it.
For this demo, we'll try to open the Pluralsight website using the WebDriver.
As you can see, all the code you'll need for this demo is prewritten.
Let's go through it step by step.
First, we'll import the WebDriver from Selenium.
Then, we'll initialize the Chrome driver.
Here,
in case you made the Chrome driver accessible via the
PATH variable of the operating system, this is all you need to type.
If you haven't or if you run into errors doing that,
you can simply manually specify the file path like this.
This is the command to open up the web page.
As you can see, once it is executed, a Chrome tab opens up displaying the site.
And if you'd like to close the web page, this is how you do it.
While doing this,
you can also specify that you want certain things to
happen a certain way with Chrome options.
You can add arguments,
such as you want the website to open up in an incognito tab or
you want the window to be a certain size,
etc.
Here, we are adding the argument for a headless browser.
What is the headless browser?
Headless browsers are web browsers without a graphical user interface,
or GUI,
and are usually controlled programmatically or via command line interface.
In simple terms,
you wouldn't be able to see the page opening up like you did before.
There are many reasons to use headless browsers,
not the least of which is the performance boost you
receive from lacking the GUI.
And this will particularly be noticeable in case you're
opening up several windows with multiple tabs.
Also,
it helps to avoid any user action on your browser during the scraping process,
which can interrupt the process flow and cost unexpected behavior.
As before, you initialize the driver with the options and fetch the page,
but this time you don't see it open up.
That's it for this demo.
We'll get into more advanced territory with the demo from the next module.