In [20]:
import requests
from bs4 import BeautifulSoup
import os

In [2]:
r = requests.get("http://pythonforengineers.com/pythonforengineersbook/")
data = r.text
soup = BeautifulSoup(data, "lxml")

In [29]:
for link in soup.find_all('img'):
    #print(link.get("src"))
    image = link.get("src")
    print(image)
    image = "http:" + image
    print(image)
    
    
    question_mark = image.find("?")
    image = image[:question_mark]
    image_name = os.path.split(image)[1]
    print(image, image_name)
    
    r2 = requests.get(image)
    with open(image_name, "wb") as f:
        f.write(r2.content)


//i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/Python_for_Scientists-small.jpg?resize=200%2C300
http://i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/Python_for_Scientists-small.jpg?resize=200%2C300
http://i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/Python_for_Scientists-small.jpg Python_for_Scientists-small.jpg
//i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/abba_face_detected.jpg?resize=345%2C319
http://i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/abba_face_detected.jpg?resize=345%2C319
http://i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/abba_face_detected.jpg abba_face_detected.jpg
//i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/motion2.jpg?resize=150%2C150
http://i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/motion2.jpg?resize=150%2C150
http://i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/motion2.jpg motion2.jpg
//i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/noisy4.png?resize=545%2C407
http://i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/noisy4.png?resize=545%2C407
http://i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/noisy4.png noisy4.png
//i1.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/audacity3.jpg?resize=715%2C299
http://i1.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/audacity3.jpg?resize=715%2C299
http://i1.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/audacity3.jpg audacity3.jpg
//i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/Marvin_HHGG.jpg?resize=184%2C302
http://i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/Marvin_HHGG.jpg?resize=184%2C302
http://i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/Marvin_HHGG.jpg Marvin_HHGG.jpg
//i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/300px-RaspberryPi.jpg?resize=300%2C200
http://i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/300px-RaspberryPi.jpg?resize=300%2C200
http://i0.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/300px-RaspberryPi.jpg 300px-RaspberryPi.jpg
//i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/rpi.jpg?resize=635%2C443
http://i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/rpi.jpg?resize=635%2C443
http://i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/rpi.jpg rpi.jpg

In [21]:



Out[21]:
'http://i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/rpi.jpg'

In [22]:
# Playing around
image


Out[22]:
'http://i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07/rpi.jpg'

In [24]:
os.path.split(image)


Out[24]:
('http://i2.wp.com/pythonforengineers.com/wp-content/uploads/2014/07',
 'rpi.jpg')

In [25]:
os.path.split(image)[1]


Out[25]:
'rpi.jpg'

In [ ]: