This program is a web scraper that uses Selenium to automate the process of exporting CSVs from Ahrefs for a list of URLs.
The program takes a list of URLs from a text file, logs into Ahrefs, and downloads the CSVs for the top 10 organic keywords for each URL. It then merges all the CSVs into one file and cleans it up before exporting it to an Excel file.
To use this program, you need to install the following Python packages:
selenium
webdriver_manager
pandas
openpyxl
You can install them using pip:
Copy code
pip install selenium webdriver_manager pandas openpyxl
You also need to download the appropriate version of the ChromeDriver executable for your system and put it in your PATH.
- Create a file named
urls.txt
in the same directory as the Python script. - Add the URLs you want to scrape to
urls.txt
, with each URL on a separate line. - Run the Python script in your terminal with
python ahrefs_scraper.py
. - Wait for the program to complete its run, then check for the output Excel file named with the top keyword.
The program works as follows:
- Reads the
urls.txt
file and converts it into a dictionary of URLs. - Launches the Chrome browser using Selenium.
- Logs into Ahrefs using your credentials.
- For each URL in the dictionary:
- Enters the URL into the search box.
- Downloads the CSVs for the top 10 organic keywords for that URL.
- Merges the downloaded CSVs into one file.
- Cleans up the merged file and exports it to an Excel file.
- Closes the browser.
The program uses various functions and libraries to achieve the above functionality. These include webdriver
, time
, pandas
, os
, re
, openpyxl
, and selenium
.
This script is for educational purposes only. Use it at your own risk. The author does not guarantee the accuracy, reliability, or suitability of this script for any purpose. The author is not responsible for any damage or loss caused by the use of this script.