Thales Marques
Thales Marques

Reputation: 353

Problems with xpath on scrapy

I'm using Scrapy to create a crawler.

I want to extract only the title of the links that I will found.

This is the current part of the code that it's important to me:

<a class="cor-produto busca-titulo" title="Melhorar a saúde, economia de tempo e dinheiro: Veja os benefícios do uso da bicicleta" href="//g1.globo.com/busca/click?q=economia&amp;p=0&amp;r=1472008380299&amp;u=http%3A%2F%2Fg1.globo.com%2Fma%2Fmaranhao%2Fjmtv-2edicao%2Fvideos%2Fv%2Fmelhorar-a-saude-economia-de-tempo-e-dinheiro-veja-os-beneficios-do-uso-da-bicicleta%2F5256064%2F&amp;t=informacional&amp;d=false&amp;f=false&amp;ss=8bcd843f636c6982&amp;o=&amp;cat=a">Melhorar a saúde, economia de tempo e dinheiro: Veja os benefíc...</a>

I want to extract only the title and I need to use xpath to do this. Anyone have any suggestion?

Thank you! :)

Upvotes: 1

Views: 88

Answers (1)

The XPath would be:

//a/@title

Being sel your Selector instance:

sel.xpath('//a/@title').extract()

Or maybe just from the response object:

response.xpath('//a/@title').extract()

Output:

Melhorar a saúde, economia de tempo e dinheiro: Veja os benefícios do uso da bicicleta

Upvotes: 1

Related Questions