Counting HTML images with Python

Posted by user2537246 on Stack Overflow See other posts from Stack Overflow or by user2537246
Published on 2013-06-30T22:15:38Z Indexed on 2013/06/30 22:21 UTC
Read the original article Hit count: 245

Filed under:
|

I need some feedback on how to count HTML images with Python 3.01 after extracting them, maybe my regular expression are used properly.

Here is my code:

import re, os
import urllib.request
def get_image(url):
  url = 'http://www.google.com'
  total = 0
  try:
    f = urllib.request.urlopen(url)
    for line in f.readline():
      line = re.compile('<img.*?src="(.*?)">')
      if total > 0:
        x = line.count(total)
        total += x
        print('Images total:', total)

  except:
    pass

© Stack Overflow or respective owner

Related posts about operating-system

Related posts about urllib