How to Prevent Web Scraping by Blocking Proxies with IP Geolocation
Over the past decade helping clients stop harmful web scraping, I‘ve seen practically every trick in the book. My name‘s John, and I‘m the head of data security for a web protection firm. In this post, I‘ll share techniques, tools, and hard-won experience helping sites restrict scrapers, especially those abusing proxies to evade detection.
After seeing numerous client sites plagued by aggressive scraping from unnamed competitors, our team developed an expertise in blocking these scrapers without impacting legitimate users. IP geolocation emerged as a key technique in our anti-scraping arsenal. Combined intelligently with other protections, it can identify telltale signs of proxy use.
Why Companies Scrape Data – And Why Sites Want to Stop Them
Before digging into blocking proxies, let‘s briefly cover why web scraping happens in the first place. Via scripts or dedicated scraping bots, companies harvest data from across the web for various reasons:
- Aggregating price data from multiple stores for comparison shopping engines
- Analyzing social media posts for investment analytics or brand monitoring
- Grabbing news articles from media sites to train AI models
- Building alternative search engine indexes drawing from multiple sources
These cases and others demonstrate web scraping powers beneficial applications. But unchecked scraping can negatively impact the scraped sites by overloading servers, violating terms of use, or enabling content theft.
Over the past 5 years, our team has seen web scraping attacks against client sites double year over year. Abuse ranges from overt denial-of-service attacks to covert data harvesting by rivals. Last year, over 30% of sites faced harmful scraping.
Just last month, we mitigated a series of scraping attacks against an e-commerce site stemming back to a rogue partner. By rotating tens of thousands of residential proxies to mask their activity, they evaded basic IP blocks. But our layered protections uncovered their abnormally high traffic volumes from odd locations. Geolocation was pivotal in flagging anomalies for deeper inspection.
Common Evasion Tactics Scrapers Use
From real-world cases, we‘ve documented scrapers utilizing three primary tactics to avoid blocks:
Proxy Rotation
By cycling through a vast pool of proxy servers to channel requests, scrapers prevent any single proxy IP from raising red flags for overuse. Residential proxies registered to real households prove hardest to combat. The traffic blending into typical household internet activity avoids triggering volume thresholds.
To counteract, we maintain an updated database logging dates, times, frequencies, and patterns of use across millions of proxies. Repeated cycles of use across our client base help identify abusive services for blocking.
Cloud Hosts and Data Centers
Major cloud providers like AWS and Azure have expansive IP ranges hosting countless customer applications. With legitimate traffic as cover, scrapers try hiding their activity among other cloud tenant requests.
While we can‘t just block entire cloud networks, carefully tuned usage limits on their IP subsets containing scrapers help curtail abuse. Allowances ensure legitimate customer requests proceed while throttling excessive volumes characteristic of scraping campaigns.
Faking Browser Environments
Scrapers fake legitimate browsers via spoofed user agent strings and headless browser automation. This makes their requests appear indistinguishable from normal human site activity.
Analyzing subtler signals like UI interactions and lifecycle journeys unmasks scrapers taking eerily straight-line paths blind users wouldn‘t replicate. We also employ cryptographic challenges proving browser environments aren‘t simulated.
Leveraging IP Geolocation
IP geolocation plays an integral role detecting proxy use by uncovering location irregularities. Each IP address ties back to a registered geography. We leverage this to catch proxies in two ways:
First, we extract the IP geography tied to an incoming request and compare it to any account details associated like usernames or billing locations. Mismatched locales may indicate proxy use rather than direct site access.
We also gauge geography against internal site analytics revealing where customers typically connect from. Abnormal activity from distant areas rings proxy alarm bells. Analyzing historical logs allows tuning location parameters staying ahead of the latest proxy regions.
Here‘s a walkthrough of adding IP geolocation to uncover proxies in Python:
import requests
import json
import ipaddress
API_KEY = ‘1234567890abc‘
# Function accepts IP address
def get_ip_geo(ip_address):
request_url = f‘https://ipgeolocation.abstractapi.com/v1/?api_key={API_KEY}&ip_address={ip_address}‘
try:
response = requests.get(request_url)
geo_data = json.loads(response.text)
return {
"error": False,
"data": geo_data
}
except Exception as error:
return {
"error": True,
"message": str(error)
}
# Main script execution
user_ip = extract_user_ip() # However you grab IP
ip_geo_result = get_ip_geo(user_ip)
if not ip_geo_result["error"]:
ip_country = ip_geo_result["data"]["country"]
if ip_country != user_billing_country:
# Likely proxy, flag for review
While effective, IP geolocation can‘t stand by itself grabbing every proxy. Let‘s examine additional layers that bolster scraping defenses.
Complementary Tools and Techniques
Blocking proxies hinges on applying an adaptive mix of protections in tandem:
User Monitoring
Recording activity histories for each account aids proxy discovery when recent logins shift locations drastically signaling proxy use. Comparing IP vs. account geographies offers corroborating signals.
Traffic Analysis
Abnormal daily/weekly cycles distinguish proxy scrapers from human schedules. Likewise, they rarely replicate natural reading/scrolling behaviors when consuming pages.
Terms of Service
Scraping policies in Terms lay the groundwork for reasonable efforts inhibiting abuse. But don‘t make public data inaccessible without justification.
Rate Limiting
Gradually throttling usage prevents scraper damage rather than outright blocking them. Minimum courtesy allowances ensure legitimacy.
Legal Action
When scraping persists despite restrictions, civil suits or criminal charges provide recourse for ToS breaches, especially around data theft.
Constant Evolution
Regularly tune limits and rules staying ahead of scraper innovations. What blocks proxies today might not tomorrow when they switch tactics.
While essential in the blocking arsenal, IP geolocation can‘t solo identify all proxy traffic. Dedicated scrapers purposefully mask their activity across various dimensions. Combined with robust Terms policies, savvy engineering provides the best path to getting relief while respecting fair legal use.
Key Takeaways Defending Your Site
Through helping sites control data scraping for years, central lessons have crystallized around combating abuse without hampering legitimate customers:
- Implement a cocktail of ever-evolving tactics – No single solution thwarts all scraper techniques as they constantly shift tactics
- Funnel protections through ToS and AUP – Transparent policies justify enforcement actions responding to violations
- Temper restrictions to match intrusion severity – Gradually throttle activity rather than instantly blocking traffic providing flexibility distinguishing friends from foes
- Make determinations based on usage, not content – Base usage limits on behavior rather than data types accessed to enable fair use cases
- Carefully assess effectiveness and adjust – Ongoing tuning ensures blocks deter scrapers without catching innocent users in the crossfire
With this balanced framework empowering you to take action limiting scrapers, your site‘s performance and security rests on more solid footing. Web scraping can provide value or inflict harm depending on implementation and ethics. Hopefully the insights here help tip the scales in favor of responsible data collection.
What other tips have you found useful thwarting bad scraping bots? I‘d love to hear what works for you in the comments below!