Jordan Scrapes Secretary of State: Maine
Tags: webscraping, axios, cheerio, secretaryofstate
Published: 2020-07-21 11:46:29

---
title: Jordan Scrapes Secretary of State: Maine
published: true
date: 2020-06-22 15:48:00 UTC
tags: WebScraping,Axios,cheerio,secretaryofstate
canonical_url: https://javascriptwebscrapingguy.com/jordan-scrapes-secretary-of-states-maine/?utm_source=rss&utm_medium=rss&utm_campaign=jordan-scrapes-secretary-of-states-maine
---

[Demo code here](https://github.com/aarmora/jordan-scrapes-secretary-of-states/tree/master/src/maine)

Warning! Maine is quick to block IP addresses. As of writing this post, I’m still unable to visit their site from my the same IP address I originally started scraping from. If you intend on scraping Maine’s secretary of state, I recommend using a proxy service. I personally use [scraperapi](https://www.scraperapi.com/?fpr=jbsg) (affiliate link) .

**Update:** Looks like after two days Maine’s site is no longer blocking me. I guess the block isn’t permanent.

**Updates 2:** Okay, just kidding. It let me in for a second and then blocked me again.

This is my 13th post in the [Secretary of State of scraping series](https://javascriptwebscrapingguy.com/secretary-of-states/). Maine was chosen because I opened a map of the United States and started at the top right and that was Maine.

## Investigation

![maine gif](https://media.giphy.com/media/tsTrqVtjOCtgBSCamg/giphy.gif)<figcaption>This just felt like Maine to me.</figcaption>

I try to look for the most recently registered businesses. They are the businesses that very likely are trying to get setup with new services and products and probably don’t have existing relationships. I think typically these are going to be the more valuable leads.

If the state doesn’t offer a date range with which to search, I’ve discovered a trick that works pretty okay. I just search for “2020”. 2020 is kind of a catchy number and because we are currently in that year people tend to start businesses that have that name in it.

Once I find one of these that is registered recently, I look for a business id somewhere. It’s typically a query parameter in the url or form data in the POST request. Either way, if I can increment that id by one number and still get a company that is recently registered, I know I can find recently registered business simply by increasing the id with which I search.

![maine secretary of state details page](https://javascriptwebscrapingguy.com/wp-content/uploads/2020/06/image.png)

Maine was a bit different in that it had two characters appended to the end of the incrementing id. I believe DC was for someting like “Domestic Company”. It also had FC for what I believe is “Foreign Company”. Once I put this together, it was very simple to just append the type of company I wanted to the end of the id and be in business.

## The code

![maine gif](https://media.giphy.com/media/1kTRz83sRtJokOFeXa/giphy.gif)

Super simple scrape. Just loop through the ids you want and grab the information. One function for the details and then a function to loop through the ids and increment them.

```
(async () => {
	const startingId = 20207298;

	for (let i = 0; i < 20; i++) {
		const business = await getDetails(startingId + i);

		console.log('Business', business, startingId + i);

		await timeout(5000);
	}

})();
```

And here’s the function that gets the data from the details page:

```
async function getDetails(id: number) {
	const url = `https://icrs.informe.org/nei-sos-icrs/ICRS?CorpSumm=${id}DC`;

	const axiosResponse = await axios.get(url);

	const $ = cheerio.load(axiosResponse.data);

	const title = $('table > tbody > tr:nth-of-type(3) > td > table > tbody > tr:nth-of-type(5) td:nth-of-type(1)').text();
	const filingDate = $('table > tbody > tr:nth-of-type(3) > td > table > tbody > tr:nth-of-type(7) td:nth-of-type(1)').text();
	const agentInformation = $('table > tbody > tr:nth-of-type(3) > td > table > table > tbody > tr:nth-of-type(12) td:nth-of-type(1)').text();

	const business = {
		title: title,
		filingDate: filingDate,
		agentInformation: agentInformation
	};

	return business;

}
```

As usual, I used [axios](https://github.com/axios/axios) for the web requests and [cheerio](https://github.com/cheeriojs/cheerio) for the html parsing. And I literally think that may be it.

## Looking for business leads?

Using the techniques talked about here at [javascriptwebscrapingguy.com](https://javascriptwebscrapingguy.com), we’ve been able to launch a way to access awesome business leads. Learn more at [Cobalt Intelligence](https://cobaltintelligence.com)!

The post [Jordan Scrapes Secretary of State: Maine](https://javascriptwebscrapingguy.com/jordan-scrapes-secretary-of-states-maine/) appeared first on [JavaScript Web Scraping Guy](https://javascriptwebscrapingguy.com).