Unlimited IP Pool
Cost Effective IP Pool
Unlimited IP Pool
Cost Effective IP Pool
Data Sourcing for LLMs & ML
Accelerate ventures securely
Proxy selection for complex cases
Some other kind of copy
Protect your brand on the web
Reduce ad fraud risks
Every day, 1.3 billion images are shared on Instagram. Many of these posts include hashtags, which are used to increase exposure on Instagram. It’s customary for companies to scrape hashtags and geolocate them to analyze and understand their target audience and preferences. They can then use the information to create relevant content while considering the costs and benefits of their marketing strategies.
Businesses from various industries use the data collected from hashtag scraping and geolocation to make informed decisions about audience segmentation, content creation, and marketing strategies.
In this guide, we’ll walk through the step-by-step process of scraping Instagram hashtags and geolocating them on the map using The Social Proxy’s scraper and Geolocate Lookup APIs. You’ll learn how to set up your environment, scrape Instagram hashtag data, geolocate images, and visualize the results on a map.
The Social Proxy is a leader in the data collection industry, offering secure and efficient data scraping and geolocation. With its developer-friendly APIs, you can extract valuable insights from Instagram while complying with data protection regulations. In this guide, we’ll use two of its powerful tools: the Scraper API and the geolocate lookup API.
The Scraper API is a cutting-edge tool that enables developers, businesses, and analysts to mine rich data from Instagram. It mimics user behavior by sending requests to Instagram to retrieve posts based on specified hashtags. Complying with ethical guidelines, the API offers a high success rate, speed, and scalability to handle large amounts of data. Businesses use it to monitor trends, identify target audiences, and analyze competitor strategies.
The Geolocate Lookup API complements the Scraper API by adding a geographical context to the extracted data. It analyzes the metadata and content of Instagram images to estimate the location where the photo was taken or posted. This API is fast, efficient, and compatible with Google Maps for location determination. E-commerce companies use it to optimize location-based marketing by understanding local consumer trends.
Follow this guide to ensure the necessary tools and APIs are ready.
On the buy proxies page, select “AI Scrapers,” choose your subscription type, and click “Go to checkout” to complete your purchase.
Make a payment on the payment page, and click “Sign up now.” Now you can start using the Scraper API.
In order to use the Scraper API, you’ll need to generate your API keys. Select “Scraper API” in the side menu and click on the “Scraper API” tab.
Click on “Generate API KEY.”
Note: You can use the keys to scrape Instagram hashtags and to geolocate the scraped images.
Make sure you copy your Consumer Key and Consumer Secret immediately before they are hidden. Keep these keys secure, as we’ll use them in our script.
Before we start scraping, we have to select which hashtag to scrape. Here are some things to consider:
In this example, we’ll use the hashtag “#bestpizza.” Feel free to replace it with a hashtag relevant to your project. In order to use The Social Proxy Scraper API to get the hashtag info on Instagram, you’ll need to write a script to make a GET call to the following endpoint:
API endpoint:
GET /wp-json/tsp/instagram/v1/tags/info
In your code editor, implement the following code to use the Scraper API to fetch data for the tagName:
import requests
import json
url = "https://thesocialproxy.com/wp-json/tsp/instagram/v1/tags/info?consumer_key=[CONSUMER_KEY]&consumer_secret=[CONSUMER_SECRET]&tagName=bestpizza"
payload = {}
headers = {
'Content-Type': 'application/json',
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.json())
Note: In the code examples, you’ll need to replace {CONSUMER_KEY} and {CONSUMER_SECRET} with your actual keys from The Social Proxy Scraper API.
Here is a breakdown of what the code does:
Here is the output:
Based on the results, the Instagram hashtag “bestpizza” has 10,000 media posts and does not follow or have any followers.
Geolocation of scraped images is basically about determining the geographical location of an image. In this case, we want to determine where an Instagram image of the hashtag “bestpizza” was captured or uploaded.
There are two ways to geolocate scraped images using The Social Proxy.
Now that we have our Instagram hashtag data, let’s use The Social Proxy’s Geolocate Lookup API to identify the geographical coordinates of images associated with this scraped hashtag.
The same API keys used in scraping will also be used in geolocating the scraped images. Here is an image we have chosen from the sample hashtag “bestpizza” which we scraped:
To use The Social Proxy Geolocate Lookup API to determine where the above Instagram image was captured or posted, you’ll write a script to make a POST call to the following endpoint.
API endpoint:
POST /wp-json/tsp/geolocate/v1/image
In your code editor, implement the following code to use the Geolocate Lookup API to fetch data for the image:
import requests
import json
url = "https://thesocialproxy.com/wp-json/tsp/geolocate/v1/image?consumer_key=[CONSUMER_KEY]&consumer_secret=[CONSUMER_SECRET]"
payload = json.dumps({
"image": "{BASE64_IMAGE}"
})
headers = {
'Content-Type': 'application/json',
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Note: In the code examples, you’ll need to replace {CONSUMER_KEY} and {CONSUMER_SECRET} with your actual keys from The Social Proxy Scraper API. Also, you’ll need to replace {BASE64_IMAGE} with the Base64 encoded version of your chosen image.
Here is a breakdown of what the code does:
Here is the output:
Based on the results, this Instagram image for the hashtag “bestpizza” was captured in Doha, Qatar. While there are other potential locations on the result, the highest probability location is at 8GGQ+G2H, Doha, Qatar, with a similarity score of 0.019222706734422706.
Sometimes scraped images won’t have geolocation data. In those types of cases, you can choose to discard the image. You can also choose to estimate the location based on user profiles or user data, tagged locations, or even the user’s last known geolocation.
There are different tools for visualizing the geolocated data on the map. Most developers use these two:
For this step, we will use Google Maps API. But you can do something similar using Leaflet.
Plotting coordinates
To plot coordinates using the Google Maps platform, you’ll need to set it up. If you have an account, sign in. If you don’t have an account, click “Get started.”
You’ll be redirected to Google Cloud console to create an account. Next, you get your API key. You’ll need it in the code for plotting the coordinates.
Set up a basic HTML structure to load the map. Then implement the following code:
Instagram Hashtag Geolocation
Note: In the code examples, you’ll need to replace YOUR_API_KEY with your actual Google Maps API key. You’ll also need to replace the lat and lng figures and cities with your actual figures and cities.
You can enhance the usability of your map by adding interactive elements, layers, and markers. You can:
Replace the default markers with custom icons to make it more visually appealing.
Add information windows that show details when users click on a marker.
Adjust the zoom level or size as needed.
In this blog, we reviewed how to effectively set up your coding and scraping environment, use the Scraper API for scraping your chosen hashtag, geolocate the scraped images using the Geolocate Lookup API, and visualize the location on a map using Google Maps API or any other mapping tool of your choice. By using The Social Proxy’s Scraper and Geolocate APIs, you can fetch valuable geographic Instagram data that can help you make informed marketing decisions, conduct, trend analysis, and more. Start leveraging Instagram hashtag data for your projects. Sign up for The Social Proxy Scraper API today and get free access to the dashboard.