[英]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.我正在通过 chrome 使用 css 选择器来获取网页上的图像,但它返回一个包含一个元素的列表,其中包含一个长字符串,其中包含我正在寻找的元素之一。 How can I get the image with the "data-src" tag.
如何获取带有“data-src”标签的图像。
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"但我想提取第一个“data-src”
I've tried a lot of combinations, select_one, get_text(), find, findall, but I keep getting return type none.我尝试了很多组合,select_one、get_text()、find、findall,但我一直得到返回类型无。
Thanks谢谢
How about this?这个怎么样?
image = soup.select("#articulo_contenedor > figure > img")
src = image[0]['data-src']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.