In this web scraping tutorial, we'll take a look at how to scrape job listing data from Indeed.com. A one of the most popular job listing websites, and it's straightforward to scrape!
In this tutorial, we'll build our scraper with just a few lines of Python code. We'll take a look at how Indeed's search works to replicate it in our scraper and extract job data from embedded javascript variables. Let's dive in!
This tutorial covers popular web scraping techniques for education. Interacting with public servers requires diligence and respect and here's a good summary of what not to do:
Do not scrape at rates that could damage the website.
Do not scrape data that's not available publicly.
Do not store PII of EU citizens who are protected by GDPR.
Do not repurpose the entire public datasets which can be illegal in some countries.
Scrapfly does not offer legal advice but these are good general rules to follow in web scraping
and for more you should consult a lawyer.
Why Scrape Indeed.com?
The job market is dynamic, featuring new opportunities and updates daily. Scraping Indeed allows for receiving real-time updates for different job postings in different industries and locations.
Scraping Indeed also allows for studying the job market trends. This is achieved by aggregating the job data to identify patterns, in-demand skills and job requirements.
Moreover, manually exploring thousands of job listings on the website can be time-consuming. However, we can quickly scrape Indeed for these listings or set up custom job posting alerts.
Project Setup
For this web scraper, we'll only need an HTTP client library such as httpx, which can be installed through pip console command:
$ pip install httpx
There are many HTTP clients in Python like requests, httpx, aiohttp, etc. However, we recommend httpx as it's the least one likely to be blocked, as it supports http2 protocol. Moreover, httpx also allows us to execute our web scraping code asynchronously, increasing our web scraping speed.
For ScrapFly users, we'll also be providing code versions using scrapfly-sdk.
Finding Indeed Jobs
To start, let's take a look at how we can find job listings on Indeed.com.
Go to the website homepage, submit a search, and you will be redirected to a search URL with a few key parameters:
https://www.indeed.com/jobs?q=python&l=Texas
So, for example, to find Python jobs in Texas, all we have to do is send a request with l=Texas and q=Python URL parameters:
from scrapfly import ScrapflyClient, ScrapeConfig
scrapfly = ScrapflyClient(key="YOUR SCRAPFLY KEY")
result = scrapfly.scrape(ScrapeConfig(
url="https://www.indeed.com/jobs?q=python&l=Texas",
asp=True,
))
print(result.selector.xpath('//h1').get())
Note: if you receive response status code 403 here, it's likely you are being blocked. Run the ScrapFly code tabs to avoid blocking.
We got a single page that contains 15 job listings! Before we collect the remaining pages, let's see how we can parse job listing data from this response.
We could parse the HTML document using CSS or XPath selectors, but there's an easier way: we can find all of the job listing data hidden away deep in the HTML as a JSON document:
This type of data is commonly known as hidden web data. It is the same data present on the web page but before it gets rendered in HTML.
So, let's parse this data using a simple regular expression pattern:
import re
import json
from scrapfly import ScrapflyClient, ScrapeConfig
scrapfly = ScrapflyClient(key="YOUR SCRAPFLY KEY")
def parse_search_page(html: str):
data = re.findall(r'window.mosaic.providerData\["mosaic-provider-jobcards"\]=(\{.+?\});', html)
data = json.loads(data[0])
return {
"results": data["metaData"]["mosaicProviderJobCardsModel"]["results"],
"meta": data["metaData"]["mosaicProviderJobCardsModel"]["tierSummaries"],
}
result = scrapfly.scrape(
ScrapeConfig(
url="https://www.indeed.com/jobs?q=python&l=Texas",
asp=True,
)
)
print(parse_search_page(result.content))
In our code above, we are using a regular expression pattern to select mosaic-provider-jobcards variable value, load it as a python dictionary and parse out the result and paging meta-data.
Now that we have the first page results and total page count, we can retrieve the remaining pages:
Python
ScrapFly
import asyncio
import httpx
import json
import re
from urllib.parse import urlencode
def parse_search_page(html: str):
data = re.findall(r'window.mosaic.providerData\["mosaic-provider-jobcards"\]=(\{.+?\});', html)
data = json.loads(data[0])
return {
"results": data["metaData"]["mosaicProviderJobCardsModel"]["results"],
"meta": data["metaData"]["mosaicProviderJobCardsModel"]["tierSummaries"],
}
async def scrape_search(client: httpx.AsyncClient, query: str, location: str, max_results: int = 50):
def make_page_url(offset):
parameters = {"q": query, "l": location, "filter": 0, "start": offset}
return "https://www.indeed.com/jobs?" + urlencode(parameters)
print(f"scraping first page of search: {query=}, {location=}")
response_first_page = await client.get(make_page_url(0))
data_first_page = parse_search_page(response_first_page.text)
results = data_first_page["results"]
total_results = sum(category["jobCount"] for category in data_first_page["meta"])
# there's a page limit on indeed.com of 1000 results per search
if total_results > max_results:
total_results = max_results
print(f"scraping remaining {total_results - 10 / 10} pages")
other_pages = [make_page_url(offset) for offset in range(10, total_results + 10, 10)]
for response in await asyncio.gather(*[client.get(url=url) for url in other_pages]):
results.extend(parse_search_page(response.text))
return results
import json
import re
from urllib.parse import urlencode
from scrapfly import ScrapflyClient, ScrapeConfig
scrapfly = ScrapflyClient(key="YOUR SCRAPFLY KEY")
def parse_search_page(html: str):
data = re.findall(r'window.mosaic.providerData\["mosaic-provider-jobcards"\]=(\{.+?\});', html)
data = json.loads(data[0])
return {
"results": data["metaData"]["mosaicProviderJobCardsModel"]["results"],
"meta": data["metaData"]["mosaicProviderJobCardsModel"]["tierSummaries"],
}
async def scrape_search(query: str, location: str, max_results: int = 50):
def make_page_url(offset):
parameters = {"q": query, "l": location, "filter": 0, "start": offset}
return "https://www.indeed.com/jobs?" + urlencode(parameters)
print(f"scraping first page of search: {query=}, {location=}")
result_first_page = await scrapfly.async_scrape(ScrapeConfig(make_page_url(0), asp=True))
data_first_page = parse_search_page(result_first_page.content)
results = data_first_page["results"]
total_results = sum(category["jobCount"] for category in data_first_page["meta"])
# there's a page limit on indeed.com of 1000 results per search
if total_results > max_results:
total_results = max_results
print(f"scraping remaining {total_results - 10 / 10} pages")
other_pages = [
ScrapeConfig(make_page_url(offset), asp=True)
for offset in range(10, total_results + 10, 10)
]
async for result in scrapfly.concurrent_scrape(other_pages):
results.extend(parse_search_page(result.content))
return results
# example run
import asyncio
asyncio.run(scrape_search(query="python", location="texas"))
Run Code & Example Output
async def main():
# we need to use browser-like headers to avoid being blocked instantly:
HEADERS = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36",
"Accept-Encoding": "gzip, deflate, br",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.9,lt;q=0.8,et;q=0.7,de;q=0.6",
}
async with httpx.AsyncClient(headers=HEADERS) as client:
search_data = await scrape_search(client, query="python", location="texas")
print(json.dumps(search_data, indent=2))
asyncio.run(main())
The search result data is similar to the following:
We've successfully scraped mountains of data with very few lines of Python code! Let's learn how to scrape job pages to obtain the remaining details of a job listing, such as the full description.
Scraping Indeed Jobs
Our search results contain almost all job listing data except a few details, such as a complete job description. To scrape this, we need the job id, which is found in the jobkey field in our search results:
{
"jobkey": "a82cf0bd2092efa3",
}
Using jobkey we can request the full job details page, and just like with the search, we can parse the hidden data instead of the HTML:
We can see that all of the job and page information is hidden in the _initialData variable. It can be extracted with a simple regular expression pattern:
Python
ScrapFly
import re
import json
import httpx
import asyncio
from typing import List
def parse_job_page(html):
"""parse job data from job listing page"""
data = re.findall(r"_initialData=(\{.+?\});", html)
data = json.loads(data[0])
return data["jobInfoWrapperModel"]["jobInfoModel"]
async def scrape_jobs(client: httpx.AsyncClient, job_keys: List[str]):
"""scrape job details from job page for given job keys"""
urls = [f"https://www.indeed.com/m/basecamp/viewjob?viewtype=embedded&jk={job_key}" for job_key in job_keys]
scraped = []
for response in await asyncio.gather(*[client.get(url=url) for url in urls]):
scraped.append(parse_job_page(response.text))
return scraped
import re
import json
from typing import List
from scrapfly import ScrapeConfig, ScrapflyClient
scrapfly = ScrapflyClient(key="YOUR SCRAPFLY KEY")
def parse_job_page(html):
"""parse job data from job listing page"""
data = re.findall(r"_initialData=(\{.+?\});", html)
data = json.loads(data[0])
return data["jobInfoWrapperModel"]["jobInfoModel"]
async def scrape_jobs(job_keys: List[str]):
"""scrape job details from job page for given job keys"""
urls = [f"https://www.indeed.com/m/basecamp/viewjob?viewtype=embedded&jk={job_key}" for job_key in job_keys]
to_scrape = [ScrapeConfig(url=url, asp=True) for url in urls]
scraped = []
async for result in scrapfly.concurrent_scrape(to_scrape):
scraped.append(parse_job_page(result.content))
return scraped
We should see the full job description printed out if we run this scraper.
With this last feature, our indeed scraper is ready to go! However, our scraper is very likely to get blocked while running it at scale. For that, let's take a look at how we can integrate ScrapFly to avoid being blocked.
Bypass Indeed Blocking with ScrapFly
Indeed.com is using anti-scraping protection to block web scraper traffic. To get around this, we can use ScrapFly web scraping API which will help you scale up!
Now, we can enable the Anti Scraping Protection bypass via the asp=True flag:
from scrapfly import ScrapflyClient, ScrapeConfig
client = ScrapflyClient(key="YOUR_API_KEY")
result = client.scrape(ScrapeConfig(
url="https://www.indeed.com/jobs?q=python&l=Texas",
asp=True,
# ^ enable Anti Scraping Protection
))
html = result.content # get the page HTML
selector = result.selector # use the built-in parsel selector
FAQ
Is it legal to scrape Indeed.com?
Yes. The job data on Indeed.com is publicly available so it's perfectly legal to scrape. Note that some of the scraped material can be protected by copyright, such as images.
Can Indeed be scraped using headless browsers such as Playwright?
Yes, but as covered in this article it's not necessary. Indeed pages are powered by a JSON API which can be scraped directly. This reduces the resource requirement for both the scraper and Indeed.com public data servers.
Is there a public API for Indeed.com?
No. As of the time of writing, there is no public API for Indeed.com job data. However, as indicated by this article Indeed.com can be easily scraped using Python!
In this short web scraping tutorial, we've looked at web scraping Indeed.com job listing search.
We built a search URL using custom search parameters and parsed job data from the embedded JSON data by using regular expressions. As a bonus, we also looked at scraping full job listing descriptions and how to avoid blocking using the Scrapfly SDK.
Learn about the fundamentals of parsing data, across formats like JSON, XML, HTML, and PDFs. Learn how to use Python parsers and AI models for efficient data extraction.