<file_sep># URL-pdf-to-file
The user is asked to search for a pdf on google. Search for ay pdf text and, the program will take that request, search it up on google using selenium and pyautogui , it will then download the pdf from the URL and save it in the current directory.
<file_sep>import pyautogui
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time
import requests
import urllib
from urllib.request import urlopen
import json
from pathlib import Path



ans = input("What do you want to search and download? ")
driver = webdriver.Chrome(ChromeDriverManager().install())

def get_website(ans1):

    
    ChromeUrl = "http://www.google.com"

    driver.get(ChromeUrl)

    driver.find_element_by_xpath("/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input")
    pyautogui.typewrite(ans1)
    driver.find_element_by_css_selector("input[class='gNO89b']").click()

    time.sleep(2)
    results = driver.find_element_by_css_selector('h3[class="LC20lb DKV0Md"]').click()  
    time.sleep(5)
    urls = driver.current_url

get_website(ans)   
urls = driver.current_url
r = requests.get(urls, allow_redirects=True) 

def is_downloadable(url):
    
    h = requests.head(url, allow_redirects=True)
    header = h.headers
    content_type = header.get('content-type')
    if 'text' in content_type.lower():
        return False
    if 'html' in content_type.lower():
        return False
    return True
print(is_downloadable(urls))

if urls.find('/'):
    filename = urls.rsplit('/', 1)[1]

filename1 = Path(filename)

response = requests.get(urls)
filename1.write_bytes(response.content)

    
input('Press ENTER to exit')
