i code a program which you give him the topic you want to download pdf of it , but it's not working well, so could anyone help me with that
from googlesearch import search
from pathlib import Path
import requests
extension = "ext:pdf"
query = "school time" extension
for result in search(query, tld="co.in", num=10, stop=10, pause=2):
print(result)
pdfnum = 0
filename = Path(pdfnum ".pdf")
url = result
response=requests.get(url)
filename.write_bytes(response.content)
pdfnum = pdfnum 1
CodePudding user response:
Python relies on indentation to determine which code block a statement belongs to (like C and Java rely on '{}'). You should try removing the indentation in the first 3 lines of your code. Their beginning should be aligned to lines 4, 5 and 6.
CodePudding user response:
Fixed indentation and type error in line 9. This code works for me:
from googlesearch import search
from pathlib import Path
import requests
extension = "ext:pdf"
query = "school time" extension
pdfnum = 0
for result in search(query, tld="co.in", num=10, stop=10, pause=2):
print(result)
filename = Path(str(pdfnum) ".pdf")
url = result
response=requests.get(url)
filename.write_bytes(response.content)
pdfnum = pdfnum 1