A Python-based scraper that searches for book titles on PDF Drive, extracts the book's download page, and retrieves the direct download link using Selenium and BeautifulSoup. The scraped data is saved in a CSV file.
- Automated Search: Finds books based on user-defined titles.
- Scrapes Download Links: Extracts the final download URL using Selenium.
- Saves to CSV: Stores book titles and download links in
Books.csv. - Headless Browsing: Uses Selenium for interacting with dynamic pages.
git clone https://github.com/CoderFek/PDF-Drive-Scrapper.git
cd srcEnsure you have Python 3.7 or later installed, then run:
pip install -r requirements.txtHow It Works (SKIP)
The script initializes a Chrome WebDriver to handle JavaScript-rendered content:
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))The script performs a search on PDFDrive, extracts relevant results, and finds the exact match:
url = f'https://www.pdfdrive.com/search?q={title}'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
search_results = soup.find_all('a', {'class': 'ai-search'})Once an exact match is found, Selenium navigates to the download page and fetches the final download link:
final_download_button = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, 'btn-user'))
)
download_href = final_download_button.get_attribute('href')The extracted book details are saved in a CSV file:
def save_to_csv(books, filename='Books.csv'):
with open(filename, mode='w', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
writer.writerow(['Title', 'Download Link'])
for book in books:
writer.writerow([book['title'], book['download_link']])- Edit the
titles_to_scrapelist inpdfDrive_scrapper.py:
titles_to_scrape = [
'''
ENTER BOOK TITLES HERE
'''
]- Run the script:
python pdfDrive_scrapper.py- Check the output in
Books.csv. Example output:
| Title | Download Link |
|--------------------|-----------------------------------------|
| Python Programming | https://www.pdfdrive.com/example-book |
| Machine Learning | https://www.pdfdrive.com/example-book |- Open
download_books.pyand add the directory path for downloaded books by editingdownload_dir.
'''
ENTER ABSOLUTE OR RELATIVE PATH OF THE DIRECTORY YOU WANT TO SAVE THE DOWNLOADED BOOKS IN.
'''
download_dir = 'Books' # To use the root directory only enter the directory name- To download books, run the script:
python download_books.py- This script is not intended for bulk downloads or unauthorized access.
- Use it responsibly and comply with website policies.
- The author is not responsible for misuse.
This project is licensed under the MIT License.