A Python 2 script to check Domain Rating (DR) and URL Rating (UR) of multiple domains using the official Ahrefs API. Results are filtered and saved to a file.
- Read a list of domains/URLs from a text file
- Automatically extract domain names from full URLs
- Query Ahrefs API for DR and UR metrics
- Save only domains that meet the threshold (default: DR > 5 OR UR > 5)
- You can change the number
5for DR/UR according to your needs (edit the condition in the script) - Retry on server errors (500) with delay
- Python 2.7
- An active Ahrefs API account with a valid API token
- Clone the repository:
git clone https://github.com/Jenderal92/ahrefs-bulk-checker.git
cd ahrefs-bulk-checker- (Optional) Create and activate a virtual environment:
virtualenv venv
source venv/bin/activate # Linux/Mac
# or
venv\Scripts\activate # Windows- Install dependencies:
pip install requestsConfiguration
Open ahrefs.py and replace the placeholder with your actual Ahrefs API token:
API_TOKEN = "your_actual_api_token_here"Never share your API token publicly. Consider using environment variables or a config file for production.
Adjusting the DR/UR Threshold
By default, the script saves domains with DR > 5 or UR > 5. You can change this value by editing the line inside main():
if dr > 5 or ur > 5: # Change the number 5 to your desired thresholdFor example, to save only domains with DR > 20 or UR > 20, change it to:
if dr > 20 or ur > 20:Usage
Prepare a text file with one domain or URL per line. For example list.txt:
example.com
https://google.com
https://www.github.com
subdomain.example.org
Run the script:
python2 ahrefs.py list.txtOutput
· Console – shows progress, API status, and each result. · res.txt – contains only domains that meet the criteria (default: DR > 5 or UR > 5), in this format:
domain: example.com | dr : 42.0 | ur : 18.5
domain: google.com | dr : 91.0 | ur : 65.0
How It Works
- Input parsing – each line is cleaned, and the domain name is extracted.
- API call – for each domain, the script sends a batch request to Ahrefs API (mode = exact, protocol = https).
- Criteria filtering – if DR > 5 or UR > 5 (or your custom value), the result is appended to res.txt.
- Delay – 1.5 seconds between requests to avoid rate limiting.
Error Handling
· Invalid/empty lines are skipped. · API errors (non-200) are printed but do not stop execution. · Server error (500) triggers up to 2 retries. · Missing file input shows a friendly error.
Limitations
· Python 2 only (legacy). For Python 3, modify print statements and dependencies. · Free Ahrefs API plan has limited requests per month – use responsibly. · No multi-threading (sequential processing).
Disclaimer
This tool is for educational and legitimate SEO analysis purposes. Respect Ahrefs API terms of service and rate limits.