Untitled
unknown
plain_text
a year ago
1.3 kB
6
Indexable
Never
import requests from bs4 import BeautifulSoup # Replace 'your_url_here' with the URL of the webpage containing the PDF url = 'http://shankar8332.pythonanywhere.com/' # Send an HTTP GET request to the webpage response = requests.get(url) # Check if the request was successful (status code 200) if response.status_code == 200: # Parse the HTML content of the webpage using BeautifulSoup soup = BeautifulSoup(response.text, 'html.parser') # Find the link to the PDF (you may need to inspect the webpage's HTML structure) pdf_link = soup.find('a', href=True, attrs={'href': lambda x: x.endswith('.pdf')}) if pdf_link: # Get the URL of the PDF pdf_url = url + pdf_link['href'] # Download the PDF file pdf_response = requests.get(pdf_url) if pdf_response.status_code == 200: # Save the PDF to a local file with open('downloaded_file.pdf', 'wb') as pdf_file: pdf_file.write(pdf_response.content) print('PDF downloaded successfully.') else: print('Failed to download the PDF.') else: print('No PDF link found on the webpage.') else: print('Failed to access the webpage.')