for imgsrc in Soup.findAll('img', {'class': 'sizedProdImage'}):
if imgsrc:
imgsrc = imgsrc
else:
imgsrc = "ERROR"
patImgSrc = re.compile('src="(.*)".*/>')
findPatImgSrc = re.findall(patImgSrc, imgsrc)
print findPatImgSrc
'''
<img height="72" name="proimg" id="image" class="sizedProdImage" src="http://imagelocation" />
This is what I am trying to extract from and I am getting:
findimgsrcPat = re.findall(imgsrcPat, imgsrc)
File "C:\Python27\lib\re.py", line 177, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
'''
find is used for returning the result when the searched element is found on the page. find_all is used for returning all the matches after scanning the entire document.
There is more simple solution:
soup.find('img')['src']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With