DEV Community

Jordan Hansen
Jordan Hansen

Posted on • Originally published at cobaltintelligence.com on

Getting great New Hampshire business leads

Demo code

New Hampshire, today we come to vanquish you (in terms of getting business leads from you).

New Hampshire Secretary of State

new hampshire secretary of state business search

Not a particularly robust search, New Hampshire’s business search allows you to search by business name with a “Contains” filter. It also has a captcha, which makes us to have to be a bit more creative with our web scraping.

Side note. There are tools that you can use to solve captchas in an automated fashion. I use 2captcha and am really happy with it. In fact, I’ve solved 85,516 captchas with them over the last 6 months.

Check them out with my shiny affiliate link here – https://2captcha.com?from=7390140

While we’re going to do the first step of this process: seeing how many pages of results we’re going to get.

So we type in the industry/keyword we are looking to target, select contains, and enter the captcha (remember, it is case sensitive). Hitting search after will give us our results after a short load time.

new hampshire business leads results

There. Searching for pizza returned 2,150 results and, more importantly for our purpose here, 86 pages. Make note of that!

Code setup

This is the part where it’s going to take a little bit of code. You will need to download git and Nodejs in order to make this work and not be too intimidated by code. It also would be helpful to have some kind of code editor, such as VS Code.

Once you have those go sign up for a free API key here. Right now Cobalt Intelligence gives 100 free requests per month and after that it’s very inexpensive for additional requests.

Now, clone the code from the github respository, install all dependencies with npm i, and open the code in VS code.

Once you’ve signed in you’ll have an API key. Copy it from here:

cobalt intelligence api key

With that API key, we’ll want to open .sample.env and replace the dummy API key in there with your actual API key.

renaming .sample.env

Run that code!

Now our code should be all set. We need to make sure to go and update the number of iterations based on the number of pages that we remembered from above.

Update this to the number of pages

With that updated we make sure that await getAllBusinesses(fileName); is commented in. It should look like this:

Run that baby with npm start. This will start Puppeteer and open a browser. You have 30 seconds to enter the keyword you are looking for, select “Contains”, do the captcha, and click on search. After that, the code will take over and do the rest. It’ll take a bit of time depending on how many pages your keyword has. So, go get some snickers or take a nap.

Step 2 of code: Getting the business leads

Okay, so the above part of the script will give us a list businesses in New Hampshire that are “Active” or in “Good Standing”. Now we need to run it through the Secretary of State API to get the owner information and contact information.

All you need to do is comment out the await getAllBusinesses(fileName); line and comment in the await getBusinessDetails(fileName); line. It should look like this:

running getBusinessDetails

This will run the rest of the code against the Secretary of State API. This could also take some time so let it run. When you get back, you should see a CSV that has the leads you’re looking for. Use it and love it.

Demo code

And here we have the video transcript:

Hello there. My name is Jordan Hansen. I’m from cobalt intelligence. And today I’m going to talk a little bit more about getting business data from New Hampshire. It’s gonna be a little bit different today. It’s going to be kind of a trick where we’re going to try to see, oh, how many businesses can. From New Hampshire from a specific category or keyword.

And the cool thing is New Hampshire. We can get through the secretary of state API here that cobalt intelligence provides. And I’m with Coldwell intelligence, you can get email addresses and phone numbers, so you can find the owner of the business and then be able to reach out to them with good contact information.

So here’s the New Hampshire secretary of state they have. It’s pretty simple. It’s not as cool as robust as some of the other ones we’ve seen to start off with. We want to go over here and. Total. We want to pick a category so we could say something like, um, let’s say we want rush or pizza pizza places or, Hmm, what’s another good one.

Um, insurance, let’s say insurance agents scare. We go over here like this, we say SDN about this capture hat and case sensitive case in CV matters here. And you hit search. Now it’s going to come over here. This is the first step you have to do. You have to come over and search for what you want, and you have to look at how many pages there are.

So for this one, there’s 238 pages. So you scroll down here to this part right here, need to update the end of the loop to match the number of pages. What do you say? We make that font even bigger. There we go. Pages. So this one would go the two them. Like that now that’s too many for this demo. Cause that will take hours, maybe hours.

I dunno a while it take a while. So what we’re going to do is we’re going to just search for something weird. We’ll just say sword, let’s say eight H N V K. We’ll search for it.

There we go. And our total of two, two pages. Okay. That makes easier. And now, now we’re gonna let the thing do its work. So this code will be, there’s a link to this code in the comments. You can go ahead and clone it and use it. Come over here. Once you update that page, the first thing is to do is update the length of the pages right there, and then you run it and it’s going to pop up.

I have this browser, it’s going to use puppet here. It’s going to pop up something we’re going to have to type in some stuff like the capture and what we’re searching for. Can we come over here work and we’ve got a sword having a capture eight, you had 30 seconds to do this G to D J search. And then once it gets it, it’ll go ahead and start paginating until the end.

So right there, bam. So you just got the first businesses. It’s going to the next one. Oh, sorry. It’s going to start in the first one right here. I give it 10 seconds for the page to load. Cause I can’t really tell what each one is. So it’s going to be 10 seconds between each page. And they’ve seen now it’s on the second one and you can see over here, see, it’s collecting the database IDs, all these businesses bam done.

So we found all these businesses right here. It actually only found eight. Now that may be weird, like, oh, why are there only eight? Well, I’m filtering out by ones that are active or in good state. If you didn’t want that, you could come over here and we move this if statement, um, and then you wouldn’t have a problem, right?

So you come over here and say, okay, active, good standing, whatever. So now that we have those, now we use the secretary of state EPA. Now you have to get an API K for the, you have to get an API key first, come over here to cobalt intelligence, get a free API key. It costs per request, but you get three requests per month.

So you can come over and use those if you want. Um, I didn’t want to print like this. You go over to the sample that in file right here. No update your API key in here and you’ll rename this file to dot M right there. So we put the APA API key in there. Then you just run this thing right here. And what that’ll do is that an open up the file that we just created oh, right down here to open the file and then it’s going to loop through them all.

And it’s going to get the data for those ones, these specific ones. So everything you can find for these active. So, and it’s going to filter them out based on the ones that have email addresses. So if there’s no email address or if it says none, that’s not going to push it into the CSV. So now we go over here, we run this guy.

Yep. Wait, give business details. Here we go. Ready? It’s going. There’s eight total. That’s correct. Now it should start looping. Bam. We got data, data, data, right? Looking good. Looking. Okay. So that means four businesses because four of them have email addresses. You can look over here, this one, no email address.

So we didn’t push it in there. We’re not interested. Maybe you are. And then you could change that if condition, no email address on that one, but there is one here. It looks you right there. And there was one here and there is one. So that’s there we go. So we’re getting email addresses now we’re done. So we’ll go here full business information.

You can see them all here with the email addresses. That’s great. And now you can just, uh, you could market to them however you want it or reach out and do whatever you wanted. And this is a way to get targeted business information in the area of New Hampshire. So you just need, um, this code and the cobalt intelligence API key.

And there you go. Go from there. That’s it. Thank you.

The post Getting great New Hampshire business leads appeared first on Cobalt Intelligence.

Top comments (0)