title: Python get image paths and sizes from a url using BeautifulSoup & PIL
body: <p>Ive successfully created a python script that can print all image paths from a specified url:</p>
  <pre><code>from requests_html import HTMLSession
  from urllib.request import urlopen
  from bs4 import BeautifulSoup
  import requests
  
  url=&quot;https://www.example.com/&quot;
  
  session = HTMLSession()
  r = session.get(url)
  
  b  = requests.get(url)
  soup = BeautifulSoup(b.text, &quot;lxml&quot;)
  
  images = soup.find_all('img')
  
  for img in images:
      if img.has_attr('src') :
          print(img['src'])
  </code></pre>
  <p>What i now want to do is print the image size alongside the printed url using PIL. Ive tried this but it errors:</p>
  <pre><code>from requests_html import HTMLSession
  from urllib.request import urlopen
  from bs4 import BeautifulSoup
  from PIL import Image
  import requests
  
  url=&quot;https://www.example.com/&quot;
  
  session = HTMLSession()
  r = session.get(url)
  
  b  = requests.get(url)
  soup = BeautifulSoup(b.text, &quot;lxml&quot;)
  
  images = soup.find_all('img')
  
  for img in images:
      if img.has_attr('src') :
          ## Get image sizes in PIL
          imgsize = Image.open(requests.get(img, stream=True).raw)
          print(img['src'], imgsize.size)
  </code></pre>
  <p>Any ideas how to get this working?</p>