In this section, we are going to learn how to start up the chromium browser with puppeteer and how
to make it visit a website.
It's quite easy.
First we are going to make a new file in the project folder.
Let's call it Index.js.
Now inside the folder, let's import puppeteer using require in the top of the file.
So const puppeteer require puppeteer.
And then let's make an async function.
It's async await is one of the newest and really cool features of JavaScript.
I'm going to leave a link in the lecture content so you can read more about it.
If you're not already familiar with this feature or if you want to read more about difference between
using then clauses and async await.
So the first thing we need to do is to tell Puppeteer to initialize or open up the chromium browser.
And doing this is really easy.
We just write out const browser equals await puppeteer launch.
And then we put in an option called Headless where we set it to false.
So now we have the browser inside this browser variable and we can access our browser and control it
from this variable.
So notice that we're using the headless false option here.
This means that the browser will not be hidden from you if you try to launch it without the headless
false option.
The browser is just going to be hidden.
Running the browser.
Headless is great.
If you already developed your scraper and you are running it on a server without a graphical interface.
But now, while we are developing and debugging our scraper, it's a pretty good advantage to see what
Puppeteer is doing in the browser and this way we can more easily debug it.
Now on to the next step, which is to open a new page or a new tab.
And then we are going to actually visit a URL.
Again.
It is super easy.
You just write out const page equals await browser new page.
And now we use the browser variable to instantiate a new page variable which we can also control.
And now we can finally make the page go to a URL.
So we say await page dot, go to and let's try out a https google.com.
Now let's try and run this script and see how it runs if we end up on Google.com.
So node and then the file index dot js.
So Puppeteer is now starting up the chromium browser and it is going to a URL and here we are on Google.com.
So there you go.
That is how you instantiate a new puppeteer controlled chromium browser, how you create a new tab or
a new page, and then make it visit a URL.
In the next section, we are going to take a closer look at the website where scraping the Craigslist
website and what kind of data we are trying to scrape.