python scrapy obtener href usando el selector css
Quiero obtener el valor href.
He intentado esto:
Link = Link1.css('span[class=title] a::text').extract()[0]
Pero solo tengo el texto dentro del <a>
.
Cómo puedo obtener el enlace dentro del href por favor
26
Author: Marco Dinatsoli, 2014-01-17
2 answers
Lo que estás buscando es:
Link = Link1.css('span[class=title] a::attr(href)').extract()[0]
Dado que estás coincidiendo con un atributo span
"class" también, puedes incluso escribir
Link = Link1.css('span.title a::attr(href)').extract()[0]
Tenga en cuenta que ::text
pseudo elemento y ::attr(attributename)
pseudo elemento funcional son NO selectores CSS3 estándar. Son extensiones de selectores CSS en Scrapy 0.20.
Editar (2017-07-20): a partir de Scrapy 1.0, puede usar .extract_first()
en lugar de .extract()[0]
Link = Link1.css('span[class=title] a::attr(href)').extract_first()
Link = Link1.css('span.title a::attr(href)').extract_first()
45
Author: paul trmbrth,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-20 15:37:12
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-07-20 15:37:12
Link = Link1.css('span.title a::attr(href)').extract_first()
5
Author: Eddy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-14 11:54:07
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-14 11:54:07