Open the browser by “Selenium”

Do a simple scraping with Selenium. This time task is Only opening the browser.
“Selenium” is a library that uses tests for the browser and automates the operation.

If you use “Selenium,” The browser is opened.

If you use “Headless,” You can scrape and operate the browser without opening.

 

Preparation

1. Install Selenium
pip install selenium
2. Chrome web driver download

pip install chromedriver-binary

However, an error occurred after executed the program.

It seemed that version of Chrome is different from the driver.

The driver is the latest Ver. 74 but browser is ver. 73.

But when I looked at Chrome’s help, Message was “No update, latest version”.

It seemed that ver. 74 beta was released just one week ago.

To solve the problem,

I downloaded the appropriate version “Exe” file from the website that I got from the error message,

And executed it on the program.

After that, I opened the webpage that had the above article and took a screenshot.
Bellow is a simple program to open a browser with “Selenium.”

===========================

#import chromedriver_binary*comment out
from selenium import webdriver
#URL setting
url = “https://www.excite.co.jp/news/article/Cobs_1890436/”
# Headless mode
options = webdriver.ChromeOptions()
options.add_argument(‘-headless’)
# Run Chrome(modified after downloaded)
browser = webdriver.Chrome(executable_path= r”d:\driver\Chromedriver.exe”,options=options)
# Load URL
browser.get(url)
# Screenshot saving
browser.save_screenshot(“website.png”)
# End
browser.quit()

===================

Result

Below is a Screenshot Extracted by selenium.
#Scraping #Selenium #python  #DataAnalysis #Computesceince #Web #Webdriver
#Chrome #test #automation