S
S
S3D8K2021-09-24 11:53:54
Python
S3D8K, 2021-09-24 11:53:54

How to get the src attribute of an img tag when parsing with BS4?

Good day.
I decided to try to implement the parsing of goods from the site asos.com.
For some reason, the parser finds links to images only for the first line, but then it does not see them.
I'm assuming it's because of the different img attribute classes.

def parsBlock(self, block):
urlBlock = block.select_one('a._3TqU78D')
nameBlock = block.select_one('a._3TqU78D')
imgBlock = block.select_one('img')

url = urlBlock.get('href ')
name = nameBlock.get('aria-label')
img = imgBlock.get('src')
price, name = (name.split('; ', 1))[1], (name.split(' ; ', 1))[0]
logger.info('%s, %s,

614d9163ad986396765125.png614d917160ac5026116008.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Mandzyuk, 2021-09-24
@Ryslan_13

1. 2.find().get("src")
find()["src"]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question