Skip to content

Scrape book titles along with their download links from a famous open-source e-book website PDF Drive.

License

Notifications You must be signed in to change notification settings

CoderFek/PDF-Drive-Scrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 PDF Drive Scraper

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.

✨ Features

  • 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.

👾 Installation

1. Clone the Repository

git clone https://github.com/CoderFek/PDF-Drive-Scrapper.git
cd src

2. Install Dependencies

Ensure you have Python 3.7 or later installed, then run:

pip install -r requirements.txt

How It Works (SKIP)

1. Setup Web Driver

The script initializes a Chrome WebDriver to handle JavaScript-rendered content:

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

2. Search for Books

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'})

3. Extract Download Link

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')

4. Save Results

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']])

✅ Usage

  1. Edit the titles_to_scrape list in pdfDrive_scrapper.py:
titles_to_scrape = [
    '''
    ENTER BOOK TITLES HERE
    '''
]
  1. Run the script:
python pdfDrive_scrapper.py
  1. 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   |
  1. Open download_books.py and add the directory path for downloaded books by editing download_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
  1. To download books, run the script:
python download_books.py

‼️ Disclaimer ‼️

  • 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.

📜 License

This project is licensed under the MIT License.

About

Scrape book titles along with their download links from a famous open-source e-book website PDF Drive.

Topics

Resources

License

Stars

Watchers

Forks

Languages