简体   繁体   中英

Get element in a list Beautiful soup

I'm using a css selector via chrome to get an image on a webpage but it returns a list with one elements that contains a long string with one of the element that I'm looking for. How can I get the image with the "data-src" tag.

my code

image = soup.select("#articulo_contenedor > figure > img")

returns

<img alt="En primera fila, de izquierda a derecha: Luis Salvador (alcalde de Granada); Luis Garicano (eurodiputado); Inés Arrimadas (portavoz en el Congreso); Edmundo Bal (portavoz adjunto); Marta Martín (diputada); y Begoña Villacís (vicealcaldesa de Madrid)." data-src="//ep01.epimg.net/politica/imagenes/2019/12/07/actualidad/1575740947_516512_1575745986_noticia_normal.jpg" data-srcset="//ep01.epimg.net/politica/imagenes/2019/12/07/actualidad/1575740947_516512_1575745986_noticia_normal_recorte1.jpg 1960w, //ep01.epimg.net/politica/imagenes/2019/12/07/actualidad/1575740947_516512_1575745986_noticia_normal_recorte2.jpg 720w, //ep01.epimg.net/politica/imagenes/2019/12/07/actualidad/1575740947_516512_1575745986_noticia_normal.jpg 980w" height="600" onload="lzld(this)" src="//ep00.epimg.net/t.gif" srcset="//ep00.epimg.net/t.gif 200w" width="980"/>

but I want to extract the first "data-src"

I've tried a lot of combinations, select_one, get_text(), find, findall, but I keep getting return type none.

Thanks

How about this?

image = soup.select("#articulo_contenedor > figure > img")
src = image[0]['data-src']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM