A program to download pdf from google | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

A program to download pdf from google

i want to write a tool which the user give it only the name of the thing he want to download pdf of it from google and the tool will search in google for it and download it for the user. as if the user want to download "computer science book" the too will search in google like >> computer science book ext:pdf and then it will visit the links and download it. i manged to do the first part which is to get the links , but I can't make the tool visit the links and download the pdfs i just need a help with the second part ##the code is try: from googlesearch import search except ImportError: print("No module named 'google' found") extension = "ext:pdf" query = "cybersecurity" + extension for j in search(query, tld="co.in", num=10, stop=10, pause=2): print(j)

29th Dec 2021, 10:23 PM
Mahmoud Hamed
Mahmoud Hamed - avatar
5 Answers
+ 2
https://docs.python-requests.org/en/latest/
29th Dec 2021, 10:26 PM
Simon Sauter
Simon Sauter - avatar
+ 2
To download files you can use requests.get(). (You may have to install the requests module first.) Take a look at the quickstart guide. https://docs.python-requests.org/en/latest/user/quickstart/#make-a-request
29th Dec 2021, 11:10 PM
Simon Sauter
Simon Sauter - avatar
0
Hello, Thank you for your help ! i have tried to use the code which you have sent but there is a problem, could you tell me what the keyword you searched for to get a result to complet my code
29th Dec 2021, 11:00 PM
Mahmoud Hamed
Mahmoud Hamed - avatar
0
try: from googlesearch import search except ImportError: print("No module named 'google' found") extension = "ext:pdf" query = "waste food" + extension i=0 for j in search(query, tld="co.in", num=10, stop=10, pause=2): print(j) from pathlib import Path import requests filename = Path(i+".pdf") url = j response = requests.get(j) filename.write_bytes(response.content) i=i+1
30th Dec 2021, 10:12 AM
Mahmoud Hamed
Mahmoud Hamed - avatar
0
i did that but still there is a problem
30th Dec 2021, 10:13 AM
Mahmoud Hamed
Mahmoud Hamed - avatar