How to download PDF files from a list of URLs in Python?

2024/11/19 18:24:32

I have a big list of links to PDF files that I need to download (500+) and I was trying to make a program to download them all because I don't want to manually do them.

This is what I have and when I try to run it, the console just opens up and closes.

import wgetdef main():f = open("list.txt", "r")f1 = f.readlines()for x in f1:wget.download(x, 'C:/Users/ALEXJ/OneDrive/Desktop/Books')print("Downloaded" + x)
Answer

The problem is that you are defining the function main() but you are not calling it anywhere else.

Here is a complete example to achieve what you want:

import wgetdef main():books_folder = 'C:/Users/ALEXJ/OneDrive/Desktop/Books'books_list = 'list.txt'with open(books_list) as books:for book in books:wget.download(book.strip(), books_folder)print('Downloaded', book)if __name__ == '__main__':main()
https://en.xdnf.cn/q/118511.html

Related Q&A

Training on GPU much slower than on CPU - why and how to speed it up?

I am training a Convolutional Neural Network using Google Colabs CPU and GPU. This is the architecture of the network: Model: "sequential" ____________________________________________________…

Check list item is present in Dictionary

Im trying to extend Python - Iterate thru month dates and print a custom output and add an addtional functionality to check if a date in the given date range is national holiday, print "NH" a…

a list of identical elements in the merge list

I need to merge the list and have a function that can be implemented, but when the number of merges is very slow and unbearable, I wonder if there is a more efficient way Consolidation conditions:Sub-…

How To Get A Contour Of More/Less Of The Expected Area In OpenCV Python

I doing some contour detection on a image and i want to find a contour based on a area that i will fix in this case i want the contour marked in red. So i want a bounding box around the red contour Fol…

Storing output of SQL Query in Python Variable

With reference to this, I tried modifying my SQL query as follows:query2 ="""insert into table xyz(select * from abc where date_time > %s and date_time <= ( %s + interval 1 hour))&…

file modification and creation

How would you scan a dir for a text file and read the text file by date modified, print it to screen having the script scan the directory every 5 seconds for a newer file creadted and prints it. Is it …

How to share a file between modules for logging in python

I wanted to log messages from different module in python to a file. Also I need to print some messages to console for debugging purpose. I used logger module for this purpose . But logger module will l…

Dont understand how this example one-hot code indexes a numpy array with [i,j] when j is a tuple?

I dont get how the line: results[i, sequence] = 1 works in the following.I am following along in the debugger with some sample code in a Manning book: "Deep Learning with Python" (Example 3.5…

convert nested list to normal list using list comprehension in python [duplicate]

This question already has answers here:How do I make a flat list out of a list of lists?(32 answers)Flatten an irregular (arbitrarily nested) list of lists(54 answers)Closed 6 years ago.How can I do t…

Transformation of pandas DataFrame adds a blank row

My original question was posted here. I have a dataframe as follows:ID START END SEQ 1 11 12 1 1 14 15 3 1 13 14 2 2 10 14 1 3 11 15 1 3 16 17 …