(Jun-23-2020, 07:12 PM)Blue Dog Wrote: I downloaded the Doc for os.(os.path.basename) Return the base name of pathname path. This is the second element of the pair returned by passing path to the function split(). what does that mean?
It helps to use interactive shell to test stuff like this,a better REPL like
ptpython or
IPython also helps.
>>> import os
>>> help(os.path.basename)
Help on function basename in module ntpath:
basename(p)
Returns the final component of a pathname
>>> url = 'http://legacy.lib.utexas.edu/maps/topo/indexes/txu-pclmaps-topo-in-index-1925.jpg'
>>> os.path.basename(url)
'txu-pclmaps-topo-in-index-1925.jpg'
So it's a simple functionality,it's not hard to write this.
>>> url = 'http://legacy.lib.utexas.edu/maps/topo/indexes/txu-pclmaps-topo-in-index-1925.jpg'
>>> url.split('/')[-1]
'txu-pclmaps-topo-in-index-1925.jpg'
Blue Dog Wrote:img = requests.get(link.get('href'))
this is a get request for all links with 'href'
No the links is already found with
find_all('a')
href
is to get bare image link out of image link tag found.
>>> map_link[0]
<a href="http://legacy.lib.utexas.edu/maps/topo/indexes/txu-pclmaps-topo-in-index-1925.jpg">Indiana - Topographic Map Index 1925</a>
>>> map_link[0].get('href')
'http://legacy.lib.utexas.edu/maps/topo/indexes/txu-pclmaps-topo-in-index-1925.jpg'
Blue Dog Wrote:with open(img_name, 'wb') as f_out:
I think this open a file that you can put Img_name in.
**************************************************************
f_out.write(img.content)
This writ the img to the file