Build a job listing scraper handling pagination and infinite scroll. Detect when the next button is disabled and use a Bloom filter to track seen job IDs to prevent re-scraping listings that appear on multiple pages.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Providing combined pagination and infinite scroll scraper
I'm preparing a Python example using requests/BeautifulSoup for paginated scraping with disabled "next" button detection plus a Selenium-based infinite scroll scraper, both employing a Bloom filter to track seen job IDs and avoid duplicates across pages.
Here's a simple pattern you can adapt to whatever job board you're targeting. It shows both a “classic” paginated flow and an infinite‑scroll flow, with a Bloom filter used to deduplicate job IDs that might appear on multiple pages.
from urllib.parse import urljoin
import requests
from bs4 import BeautifulSoup
from pybloom_live import ScalableBloomFilter
session = requests.Session()
base_url = "https://example.com/jobs"
seen = ScalableBloomFilter(initial_capacity=10_000, error_rate=0.001)
def scrape_page(url: str):
resp = session.get(url)
resp.raise_for_status()
soup = BeautifulSoup(resp.text, "html.parser")
# Extract job cards and IDs according to the site's markup
for card in soup.select(".job-card"):
job_id = card.get("data-id")
if job_id is None:
continue
if job_id in seen:
continue # already processed on another page
seen.add(job_id)
title = card.select_one(".title").get_text(strip=True)
link = urljoin(base_url, card.select_one("a")["href"])
print(job_id, title, link)
# Find a “next” link and check if it's disabled
next_btn = soup.select_one("a.next")
if next_btn is None:
return None
classes = next_btn.get("class", [])
if "disabled" in classes or next_btn.get("aria-disabled") == "true":
return None
if href := next_btn.get("href"):
return urljoin(base_url, href)
return None
# Start at page 1 and follow next links until disabled/missing
url = f"{base_url}?page=1"
while url:
url = scrape_page(url)
This assumes the “next” anchor has a .next class and a "disabled" class or aria-disabled="true" when you’re at the end. Adjust the selectors to match the real markup.
Infinite scroll
For sites that append more jobs as you scroll, you can use Selenium to trigger the scroll and re‑parse the DOM:
python
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://example.com/jobs")
seen = ScalableBloomFilter(initial_capacity=10_000, error_rate=0.001)
last_height = 0
while True:
# Parse currently loaded jobs
cards = driver.find_elements(By.CSS_SELECTOR, ".job-card")
for card in cards:
job_id = card.get_attribute("data-id")
if not job_id or job_id in seen:
continue
seen.add(job_id)
title = card.find_element(By.CSS_SELECTOR, ".title").text
link = card.find_element(By.CSS_SELECTOR, "a").get_attribute("href")
print(job_id, title, link)
# Scroll down and wait for new content to load
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2) # adjust as needed for the site's loading time
new_height = driver.execute_script("return document.body.scrollHeight;")
if new_height == last_height:
break # no more content loaded
last_height = new_height
driver.quit()
If the site uses a “Load more”/“Next” button instead of pure scroll, locate that button and use button.is_enabled()/button.get_attribute("class") to decide when to stop:
python
try:
next_button = driver.find_element(By.CSS_SELECTOR, "button.load-more")
if not next_button.is_enabled() or "disabled" in next_button.get_attribute("class"):
break
next_button.click()
time.sleep(2)
except NoSuchElementException:
break
Remember to respect the site’s terms of service and robots.txt, and throttle your requests so you don’t overload the server.