1

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! :)

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the answer. I'll test this when I get home. I believe it will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.