Advertisement
nicuf

SCRIBD download documents

Oct 28th, 2023
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. from selenium import webdriver
  2. from bs4 import BeautifulSoup
  3. import requests
  4.  
  5. def download_scribd_document(document_url, output_path):
  6.     # Initialize Selenium WebDriver
  7.     driver = webdriver.Chrome(executable_path='C:/path/to/chromedriver.exe')  # Update this path
  8.     driver.get(document_url)
  9.  
  10.     # Get page source
  11.     html = driver.page_source
  12.  
  13.     # Parse HTML with BeautifulSoup
  14.     soup = BeautifulSoup(html, 'html.parser')
  15.     download_link = soup.find('a', {'class': 'download-button'})
  16.  
  17.     if download_link:
  18.         download_response = requests.get(download_link['href'])
  19.         download_data = download_response.content
  20.  
  21.         with open(output_path, 'wb') as f:
  22.             f.write(download_data)
  23.     else:
  24.         print("Download link not found")
  25.  
  26.     driver.quit()
  27.  
  28. # Example usage
  29. document_url = 'https://www.scribd.com/document/your-document-id'
  30. output_path = 'document.pdf'
  31. download_scribd_document(document_url, output_path)
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement