

Here, we are enforcing the a elements to have href values, not checking for elements to be found (since the loop body would just not be executed in this case).Īs far as managing the urls you've already visited: You can also simplify the way you look for the links to follow: for link in lect("a"): # if there are links on the webpage then recursively repeat Soup = BeautifulSoup(''.join(urlContent)) If url in urlList: # prevent using the same URL again

# recursively download images starting from the root URLĭef downloadImages(url, level): # the root URL is level 0 import urllib2įrom bs4 import BeautifulSoup # for HTML parsing Is there a way to shorten/improve this code? Any ideas/suggestions are appreciated. The script mentioned below do grab images from URLs and put them in into a folder. I'm just beginning with Python and programming, so been trying to get as much experience reading code as possible.
