How To

Have a great idea for an article?

We're always looking for guest contributors or article suggestions. Shoot us an email at blog@intoli.com, we would love to hear yours!

Running Selenium with Headless Chrome in Ruby

NOTE: Be sure to check out Running Selenium with Headless Chrome if you’re interested in using Selenium in Python instead of Ruby. Since Google added support to run Chrome and Chromium in headless mode as of version 59, it has become a popular choice for both testing and web scraping. There are a few Chrome-specific automation solutions out there, such as Puppeteer and Chrome Remote Interface, but Selenium remains a popular choice due to it’s uniform API across web browsers and it’s support for multiple programming languages.

Continue reading

How to Clear the Firefox Browser Cache With Selenium WebDriver/geckodriver

If you use Selenium for automated testing or web scraping, you may have discovered that there is no built-in utility for clearing browser resources like cookies, cached scripts, and objects in local storage. This is not particularly surprising given that the WebDriver specification that Selenium uses behind the scenes has no provision for clearing the cache. However, lingering cached resources can cause your tests to pass when they shouldn’t, prevent your scrapers from quickly starting clean sessions on demand, and cause all sorts of undesirable behavior besides.

Continue reading

How to Run a Keras Model in the Browser with Keras.js

This article explains how to export a pre-trained Keras model written in Python and use it in the browser with Keras.js. The main difficulty lies in choosing compatible versions of the packages involved and preparing the data, so I’ve prepared a fully worked out example that goes from training the model to performing a prediction in the browser. You can find the working end-result in Intoli’s article materials repository, but do read on if you’d like just the highlights.

Continue reading

How to Exit When Errors Occur in Bash Scripts

It’s a common issue that scripts written and tested on GNU/Linux don’t run correctly on macOS–or vice versa–because of differences between the GNU and BSD versions of the core utils. Error messages can get drowned in the script output, making it far from obvious that something isn’t executing correctly. There are a couple of easy fixes to avoid problems like this, but they rely on some bash features that you may not be familiar with if you don’t do a ton of scripting.

Continue reading

Resizing Matplotlib Legend Markers

How to Resize Matplotlib Legend Markers I frequently find myself plotting clusters of points in Matplotlib with relatively small marker sizes. This is a useful way to visualize the data, but the plot’s legend will use the same marker sizes by default and it can be quite difficult to discern the color of a single point in isolation. Let’s plot a few random clusters of points to see what this problem looks like in practice.

Continue reading

How to Use a Custom SSH Identity with Git

This page describes how to specify which SSH profile to use with git. This can be handy if you have more than one GitHub account and don’t wish to reuse your default SSH key or type in a password every time you push or pull. The commands will be written from the perspective of a GitHub user, but should be easy to adapt to other scenarios as well. Step-by-Step Instructions Generate a new SSH key:

Continue reading

How to Clear the Chrome Browser Cache With Selenium WebDriver/ChromeDriver

Sometimes during the course of testing or web scraping with Google Chrome, you might desire to clear the browser cache and cookies with Selenium. You can of course call driver.close() on your current ChromeDriver instance and then provision a new one. The fresh instance of Chrome will start with a clean browser history, cookies, and cache. There are however times when this method loses other state that you may want to preserve.

Continue reading